mysql> create table tb_test(
-> id int unsigned not null auto_increment,
-> firstname varchar(25) not null,
-> lastname varchar(25) not null,
-> email varchar(45) not null,
-> phone varchar(10) not null,
-> primary key(id));
Query OK, 0 rows affected (0.03 sec)
记住,表至少包含一列。另外,创建表之后总是可以再回过头来修改表的结构。无论当前是否在使用目标数据库,都可以创建表,只要在表名前面加上目标数据库即可。例如:
复制代码 代码如下:
mysql> create table db_test.tb_test(
-> id int unsigned not null auto_increment,
-> firstname varchar(25) not null,
-> lastname varchar(25) not null,
-> email varchar(45) not null,
-> phone varchar(10) not null,
-> primary key(id));
Query OK, 0 rows affected (0.03 sec)
2.有条件的创建表