Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About create table as select (CTAS)

When we do:

create table big2 as select * from big1;

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

like image 522
Victor Avatar asked Feb 22 '23 16:02

Victor


1 Answers

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.

like image 129
Jacob Mattison Avatar answered Feb 25 '23 04:02

Jacob Mattison