我知道这句话:

create table xyz_new as select * from xyz;

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


当前回答

简单地写一个查询:

create table new_table as select * from old_table where 1=2;

其中new_table是要创建的新表的名称,old_table是要复制其结构的现有表的名称,这将只复制结构。

其他回答

SELECT * INTO newtable
FROM oldtable
WHERE 1 = 0;

使用另一个表的模式创建一个新的空表。只需添加一个WHERE子句,导致查询不返回数据:

简单地写一个查询:

create table new_table as select * from old_table where 1=2;

其中new_table是要创建的新表的名称,old_table是要复制其结构的现有表的名称,这将只复制结构。

没有表数据的复制

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

复制表数据

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

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

你也可以做

create table abc_new as select * from abc; 

然后截断表abc_new。希望这能满足你的要求。