我知道这句话:
create table xyz_new as select * from xyz;
它复制了结构和数据,但如果我只想要结构呢?
我知道这句话:
create table xyz_new as select * from xyz;
它复制了结构和数据,但如果我只想要结构呢?
当前回答
只需使用一个where子句,它不会选择任何行:
create table xyz_new as select * from xyz where 1=0;
限制
以下内容不会被复制到新表中:
序列 触发器 索引 有些约束可能无法复制 物化视图日志
这也不能处理分区
其他回答
使用sql developer选择表并单击DDL选项卡
在sql工作表中运行该代码时,可以使用该代码创建没有数据的新表
Sqldeveloper是oracle提供的一个免费应用程序。
如果表有序列或触发器,ddl有时也会为您生成这些。你只需要注意它们的顺序,知道什么时候打开或关闭触发器。
只需使用一个where子句,它不会选择任何行:
create table xyz_new as select * from xyz where 1=0;
限制
以下内容不会被复制到新表中:
序列 触发器 索引 有些约束可能无法复制 物化视图日志
这也不能处理分区
create table xyz_new as select * from xyz where rownum = -1;
避免反复迭代,并在1=2的条件下不插入任何内容
你也可以做
create table abc_new as select * from abc;
然后截断表abc_new。希望这能满足你的要求。
没有表数据的复制
create table <target_table> as select * from <source_table> where 1=2;
复制表数据
create table <target_table> as select * from <source_table>;