Tuesday 20 December 2011

My SQL show create table command

You can see the layout of a table with the desc command but if you want to see how it was created, you should use the show create table command. I had to reformat the output below to fit it on the screen. If you try it yourself, you will see what I mean:

mysql> create table andrews_table
    -> (col1 varchar(10), primary key(col1));
Query OK, 0 rows affected (0.04 sec)

mysql> desc andrews_table;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| col1  | varchar(10) | NO   | PRI |         |       |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.04 sec)

mysql> show create table andrews_table;
+---------------+-------------------------------------------+
| Table         | Create Table                              |
+---------------+-------------------------------------------+
| andrews_table | CREATE TABLE `andrews_table`              |
|               | (`col1` varchar(10) NOT NULL default '',  |
|               | PRIMARY KEY  (`col1`)) ENGINE=MyISAM      |
|               | DEFAULT CHARSET=latin1                    |
+---------------+-------------------------------------------+
1 row in set (0.00 sec)

mysql>

No comments: