Documentation Home
MySQL 8.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 37.9Mb
PDF (A4) - 37.9Mb
PDF (RPM) - 32.9Mb
HTML Download (TGZ) - 8.0Mb
HTML Download (Zip) - 8.1Mb
HTML Download (RPM) - 6.9Mb
Man Pages (TGZ) - 132.7Kb
Man Pages (Zip) - 188.9Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
Excerpts from this Manual SHOW CREATE TABLE Syntax


Shows the CREATE TABLE statement that creates the named table. To use this statement, you must have some privilege for the table. This statement also works with views.

*************************** 1. row ***************************
       Table: t
Create Table: CREATE TABLE `t` (
  `s` char(60) DEFAULT NULL,
  PRIMARY KEY (`id`)

SHOW CREATE TABLE quotes table and column names according to the value of the sql_quote_show_create option. See Section 5.1.7, “Server System Variables”.

For information about how CREATE TABLE statements are stored by MySQL, see Section, “CREATE TABLE Statement Retention”.

User Comments
  Posted by Eject Disc on October 21, 2005
This is useful when you want to change a column name or definition with:

ALTER TABLE foobar CHANGE old_field_name new_field_name old_field_definition

You want to maintain the same column type, so having the original column definition at your fingers tips is handy.

This features seems to be from 4.0 release series onwards.

  Posted by Lou Picciano on April 19, 2006
This 'ENGINE=' syntax is important; don't forget to look through your older code for similar 'TYPE=' designations. There are some well-know applications which are choking on 'TYPE=HEAP', for example, reporting a Syntax Error.

If people are not familiar with switching ENGINE types, this one can bite you!
  Posted by Matt Piskorz on May 12, 2006
You can also use create table if not exists [database].[table]

Replace [database] with the database of where the table should be created.

Replace [table] with the table name you want created.

example: (This will create a table called user in the test database)

create table if not exists test.user
UserID varchar(50)
, Password varchar(50)
) Engine=InnoDB;

  Posted by Stephen Dewey on August 14, 2006
This might go without saying for most folks, but just so you know, this statement does not necessarily return the same statement that was actually used to create the table in the first place. It returns a statement which if run at the current time will recreate the given table with its current structure (not including the data). So if you create a table, then alter it, then run the SHOW CREATE TABLE command, it will return a statement that acts as if the change represented by your ALTER command were incorporated into your initial CREATE TABLE command.
  Posted by Rodolfo Campos on March 14, 2011
At the end, if you just want to retrieve column: names, types and comments as in a data dictionary you can forget this command... I've found it too complex to parse.

You can check an script (in spanish) that I've created at:
Sign Up Login You must be logged in to post a comment.