About create table as select (CTAS)

2020-07-18 06:20发布

When we do:

create table big2 as select * from big1;

Are the indexes and constraints also copied over to the new table?

2条回答
\"骚年 ilove
2楼-- · 2020-07-18 07:06

Just for info, there is a simple way to remember indices to recreate them after deleting source table:

SELECT DBMS_METADATA.get_ddl('INDEX', index_name)
    FROM user_indexes
    WHERE TABLE_NAME = 'BIG1';
查看更多
可以哭但决不认输i
3楼-- · 2020-07-18 07:07

Only NOT NULL constraints are copied. See FAQ.

You can do CREATE TABLE big2 (bigid PRIMARY KEY) AS SELECT * FROM big1 tp create a primary key, but yes, for other indexes you'll want to copy and run the index creation scripts.

查看更多
登录 后发表回答