语法:
mysql> show tables;
语法:
Create table [if not exists] `表名`(
`字段名` 数据类型[null | not null] [default] [auto_increment] [primary key] [comment],
`字段名` 数据类型...
)[engine=存储引擎] [charset =字符编码]
null |not null 是否为空
default 默认值
auto_increment 自动增长,默认从1开始,每次递增1
primary key 主键,不能重复,不能为空
comment 备注
engine 引擎,myisam,innodb
注意:表名和字段名如果用了关键字,要用反引号包裹起来。
mysql> create table stu( -> id int auto_increment primary key, -> name varchar(20) not null -> )engine=innodb charset=gbk; Query OK, 0 rows affected (0.04 sec)
mysql> create table student( -> id int auto_increment primary key comment '主键', -> name varchar(50) not null comment '姓名', -> `add` varchar(100) not null default '地址不详' comment '地址', -> score int comment '成绩' -> )engine=myisam;
1. 如果不指定引擎,默认是innodb
2. 如果不指定字符编码,默认和数据库编码一致
3. Set names gbk; 这句话是设置客户端和服务器通讯的编码