注意 : 对表的操作必须要选定数据库.
create table 表名 (
字段名 字段类型 [字段属性],
字段名 字段类型 [字段属性],
...
) [表选项];
create table class(
id int zerofill auto_increment primary key,
name char(20) not null,
age tinyint unsigned not null
) charset utf8;
create table 新表名 like 需要复制结构的表名;
show tables;
desc 表名;
+-------+---------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------------+------+-----+---------+----------------+
| id | int(10) unsigned zerofill | NO | PRI | NULL | auto_increment |
| name | char(20) | NO | | NULL | |
| age | tinyint(4) | NO | | NULL | |
+-------+---------------------------+------+-----+---------+----------------+
show create table 表名;
alter table class
如:
alter table class engine innodb,charset utf8;
rename table 旧表名 to 新表名;
alter table 表名 add 字段名 字段类型 [字段属性] [位置];
如:
alter table 表名 add age tinyint not null unsigned comment '年龄' after height;
在表中height字段后面添加age字段无符号,微整型.
alter table 表名 change 旧字段名 新字段名 字段属性 新位置;
alter table 表名 modify 字段名 字段属性 [位置];
alter table 表名 字段名;
drop table 表1,表2;
内容来源于网络,如有侵权,请联系作者删除!