我知道这句话:
create table xyz_new as select * from xyz;
它复制了结构和数据,但如果我只想要结构呢?
我知道这句话:
create table xyz_new as select * from xyz;
它复制了结构和数据,但如果我只想要结构呢?
当前回答
你可以这样做 创建表New_table为select * from Old_table 但是要小心 您创建的表不像old_table那样具有任何Index、PK等。
其他回答
你也可以做
create table abc_new as select * from abc;
然后截断表abc_new。希望这能满足你的要求。
简单地写一个查询:
create table new_table as select * from old_table where 1=2;
其中new_table是要创建的新表的名称,old_table是要复制其结构的现有表的名称,这将只复制结构。
WHERE 1 = 0或类似的假条件可以工作,但我不喜欢它们的样子。Oracle 12c+ IMHO的代码稍微干净一些
创建表栏AS SELECT * 从foo 只获取前0行;
同样的限制适用:只有列定义及其可空性被复制到新表中。
create table xyz_new as select * from xyz where rownum = -1;
避免反复迭代,并在1=2的条件下不插入任何内容
Create table target_table
As
Select *
from source_table
where 1=2;
Source_table是你要复制其结构的表。