我知道这句话:

create table xyz_new as select * from xyz;

它复制了结构和数据,但如果我只想要结构呢?


当前回答

create table xyz_new as select * from xyz where rownum = -1;

避免反复迭代,并在1=2的条件下不插入任何内容

其他回答

以上任务可以通过两个简单步骤完成。

步骤1:

CREATE table new_table_name AS(Select * from old_table_name);

上面的查询创建了一个表的副本(包括内容)。

若要获得结构,使用删除表的内容。

步骤2:

DELETE * FROM new_table_name.

希望这能解决你的问题。感谢之前的帖子。给了我很多启发。

Create table target_table 
As
Select * 
from source_table 
where 1=2;

Source_table是你要复制其结构的表。

创建表xyz_new作为select * from xyz;

——这将创建表并复制所有数据。

Delete from xyz_new;

-这将有相同的表结构,但所有复制的数据将被删除。

如果你想克服答案中指定的限制: 如何在不复制数据的情况下创建Oracle表的副本?

没有表数据的复制

create table <target_table> as select * from <source_table> where 1=2;

复制表数据

create table <target_table> as select * from <source_table>;

使用sql developer选择表并单击DDL选项卡

在sql工作表中运行该代码时,可以使用该代码创建没有数据的新表

Sqldeveloper是oracle提供的一个免费应用程序。

如果表有序列或触发器,ddl有时也会为您生成这些。你只需要注意它们的顺序,知道什么时候打开或关闭触发器。