我知道这句话:
create table xyz_new as select * from xyz;
它复制了结构和数据,但如果我只想要结构呢?
我知道这句话:
create table xyz_new as select * from xyz;
它复制了结构和数据,但如果我只想要结构呢?
当前回答
没有表数据的复制
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是你要复制其结构的表。
SELECT * INTO newtable
FROM oldtable
WHERE 1 = 0;
使用另一个表的模式创建一个新的空表。只需添加一个WHERE子句,导致查询不返回数据:
只需使用一个where子句,它不会选择任何行:
create table xyz_new as select * from xyz where 1=0;
限制
以下内容不会被复制到新表中:
序列 触发器 索引 有些约束可能无法复制 物化视图日志
这也不能处理分区
DECLARE
l_ddl VARCHAR2 (32767);
BEGIN
l_ddl := REPLACE (
REPLACE (
DBMS_LOB.SUBSTR (DBMS_METADATA.get_ddl ('TABLE', 'ACTIVITY_LOG', 'OLDSCHEMA'))
, q'["OLDSCHEMA"]'
, q'["NEWSCHEMA"]'
)
, q'["OLDTABLSPACE"]'
, q'["NEWTABLESPACE"]'
);
EXECUTE IMMEDIATE l_ddl;
END;
create table xyz_new as select * from xyz where rownum = -1;
避免反复迭代,并在1=2的条件下不插入任何内容