一、设置默认值
设置默认值采用default,如代码所示:
二、设置取值范围
设置取值范围采用check,如代码所示:

create table student(
id int not null  primary key auto_increment,
name varchar(32) not null,
sex varchar(8) default('男'), #设置默认值
age int not null check (age between 10 and 50), #设置取值范围
class_id int not null references class(id),
stu_num varchar(32),
constraint stu_u unique(stu_num)
);
Logo

更多推荐