案例.根据需求,完成表结构的创建
create table user(
id int primary key auto_increment comment ‘主键’,
name varchar(10) not null unique comment ‘姓名’,
age int check ( age > 0 && age <= 120 ) comment ‘年龄’,
status char(1) default ‘1’ comment ‘状态’,
gender char(1) comment ‘性别’
) comment ‘用户表’;
插入数据演示
— 插入数据
insert into user(name,age,status,gender) values (‘Tom1’,19,’1’,’男’),(‘Tom2’,25,’0’,’男’);
insert into user(name,age,status,gender) values (‘Tom3’,19,’1’,’男’);
insert into user(name,age,status,gender) values (null,19,’1’,’男’);
insert into user(name,age,status,gender) values (‘Tom3’,19,’1’,’男’);
insert into user(name,age,status,gender) values (‘Tom4’,80,’1’,’男’);
insert into user(name,age,status,gender) values (‘Tom5’,-1,’1’,’男’);
insert into user(name,age,status,gender) values (‘Tom5’,121,’1’,’男’);
insert into user(name,age,gender) values (‘Tom5’,120,’男’);
课堂练习:
创建成绩表,要求如下:
1、要有主键,自动增长
2、有math、english、chinses三科成绩,默认值0
3、有姓名、年龄、性别,不能为空