Rechercher dans le manuel MySQL
13.1.20.4 CREATE TABLE ... LIKE Syntax
Use CREATE 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:
The copy is created using the same version of the table storage
format as the original table. The
SELECT
privilege is required on
the original table.
LIKE
works only for base tables, not for
views.
You cannot execute CREATE TABLE
or
CREATE TABLE ... LIKE
while a
LOCK TABLES
statement is in
effect.
CREATE TABLE ...
LIKE
makes the same checks as
CREATE 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 the statement
will fail.
For CREATE TABLE ... LIKE
, the destination
table preserves generated column information from the original
table.
For CREATE TABLE ... LIKE
, the destination
table preserves expression default values from the original
table.
For CREATE TABLE ... LIKE
, the destination
table preserves CHECK
constraints from the
original table, except that all the constraint names are
generated.
CREATE TABLE ... LIKE
does not preserve any
DATA DIRECTORY
or INDEX
DIRECTORY
table options that were specified for the
original table, or any foreign key definitions.
If the original table is a TEMPORARY
table,
CREATE TABLE ... LIKE
does not preserve
TEMPORARY
. To create a
TEMPORARY
destination table, use
CREATE TEMPORARY TABLE ... LIKE
.
Tables created in the mysql
tablespace, the
InnoDB
system tablespace
(innodb_system
), or general tablespaces
include a TABLESPACE
attribute in the table
definition, which defines the tablespace where the table
resides. Due to a temporary regression, CREATE TABLE
... LIKE
preserves the TABLESPACE
attribute and creates the table in the defined tablespace
regardless of the
innodb_file_per_table
setting.
To avoid the TABLESPACE
attribute when
creating an empty table based on the definition of such a table,
use this syntax instead:
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-create-table-like.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.