-- int unsigned 无符号整形
-- auto_increment 表示自动增长
-- not null 表示不能为空
-- primary key 表示主键
-- default 默认值
-- create table 数据表名字 (字段 类型 约束[, 字段 类型 约束]);
create table xxx(id int unsigned primary key not null auto_increment,
name varchar(20) not null
);
查看表结构
desc 数据表的名字;
事例
创建classes表
-- 创建 classes 表(id、name)
create table classes(id int unsigned primary key auto_increment not null,
name varchar(20) not null
);
创建students表
-- 创建 students 表(id、name、age、high (decimal)、gender (enum)、cls_id)
create table students(id int unsigned primary key auto_increment not null,
name varchar(20) not null,
age int unsigned,
high decimal(5,2),
gender enum("男性","女性","中性","保密") default "保密",
cls_id int unsigned
);