Mysql quick creation of an empty table bitsCN.com
How can I create an empty table? There are two methods in MYSQL.
1. create table select...
2. create table like...
The first is known to many people, but the second is rarely used.
The first has two disadvantages:
1. some definitions of the original table will be removed from the first type.
This is the case in the manual:
Some conversion of data types might occur. For example,
The AUTO_INCREMENT attribute is not preserved,
And VARCHAR columns can become CHAR columns.
However, after I tested it, the auto-increment attribute will only be canceled!
2. the engine is the default engine of the system.
The second one won't.
Let's take a look at the example:
Mysql> create table t_old (id serial, content varchar (8000) not null, 'desc' varchar (100) not null) engine innodb;
Query OK, 0 rows affected (0.01 sec)
Mysql> show create table t_old;
+ ------- + ---------------------------------------- +
| Table | Create Table |
+ ------- + -------------------------------------------------- +
| T_old | create table 't_ old '(
'Id' bigint (20) unsigned not null AUTO_INCREMENT,
'Content' varchar (8000) not null,
'Desc' varchar (100) not null,
Unique key 'id' ('id ')
) ENGINE = InnoDB default charset = utf8 |
+ ------- + ------------------------- +
1 row in set (0.00 sec)
Mysql> create table t_select select * from t_old where 1 = 0;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
Mysql> show create table t_select;
+ ---------- + ------------------------------- +
| Table | Create Table |
+ ---------- + --------------------------------------- +
| T_select | create table 't_ Select '(
'Id' bigint (20) unsigned not null default '0 ',
'Content' varchar (8000) not null,
'Desc' varchar (100) NOT NULL
) ENGINE = MyISAM default charset = utf8 |
+ ---------- + -------------------------------------------------- +
1 row in set (0.00 sec)
Mysql> create table t_like like t_old;
Query OK, 0 rows affected (0.02 sec)
Mysql> show create table t_like;
+ -------- + --------------------------------------------------- +
| Table | Create Table |
+ -------- + --------------------------------------------------------- +
BitsCN.com