create table if not exists `stu6` (`id` int not null auto_increment primary key comment '这是id',`name` varchar(10) not null default '姓名不详' comment '这是姓名的备注') engine=myisam;
复制代码
这条语句比较长,我们来解释一下:
create table --表示创建数据表
if not exists --表示如果我们要创建的数据表不存在则创建,加上这段话防止报错
`stu6` --数据表名
括号中的内容是用来定义数据表中的字段
`id` int not null auto_increment primary key comment '这是id', --这句话表示:`id`字段的数据类型为int,not null表示不允许为空,auto_increment表示自动增长,即:以后我们每插入一条数据,该字段的值都会自动加1
primary key --表示该字段为主键
comment '这是id' --定义字段的备注
注意:每个字段要以逗号结束,字段名要以反引号包裹,即主键盘左上角,数字1左边的那个按键。
逗号后面是第二个字段
`name` varchar(10) not null default '姓名不详' comment '这是姓名的备注' --`name`是字段名,varchar(10)表示该字段类型为varchar,长度为10个字节,not null表示不允许为空