Documentation Home
MySQL 9.1 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.4Mb
PDF (A4) - 40.5Mb
Man Pages (TGZ) - 259.5Kb
Man Pages (Zip) - 366.7Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.1 Reference Manual  / ...  / SQL Statements  / Data Definition Statements  / CREATE TABLE Statement  /  CREATE TABLE ... LIKE Statement

15.1.20.3 CREATE TABLE ... LIKE Statement

UseCREATE TABLE ... LIKE to create an empty table based on the definition of another table, including any column attributes and indexes defined in the original table:

CREATE TABLEnew_tbl LIKEorig_tbl;

The copy is created using the same version of the table storage format as the original table. TheSELECT privilege is required on the original table.

LIKE works only for base tables, not for views.

Important

You cannot executeCREATE TABLE orCREATE TABLE ... LIKE while aLOCK TABLES statement is in effect.

CREATE TABLE ... LIKE makes the same checks asCREATE TABLE. This means that if the current SQL mode is different from the mode in effect when the original table was created, the table definition might be considered invalid for the new mode and cause the statement to fail.

ForCREATE TABLE ... LIKE, the destination table preserves generated column information from the original table.

ForCREATE TABLE ... LIKE, the destination table preserves expression default values from the original table.

ForCREATE TABLE ... LIKE, the destination table preservesCHECK constraints from the original table, except that all the constraint names are generated.

CREATE TABLE ... LIKE does not preserve anyDATA DIRECTORY orINDEX DIRECTORY table options that were specified for the original table, or any foreign key definitions.

If the original table is aTEMPORARY table,CREATE TABLE ... LIKE does not preserveTEMPORARY. To create aTEMPORARY destination table, useCREATE TEMPORARY TABLE ... LIKE.

CREATE TABLE ... LIKE operations apply allENGINE_ATTRIBUTE andSECONDARY_ENGINE_ATTRIBUTE values to the new table.