SQL中如何限制属性取值

来源:百度知道 编辑:UC知道 时间:2024/05/02 16:43:36
在创建表时如何限制某一列的取值为1到100

使用关键字check去定义列约束就行了,例如:
...
grade number check(grade between 1 and 100),
...

like this:
create table student(
Sno int not null primary key,
age int check(age between 1 and 100)
sex char(2) check(sex in('男','女')
DempNo int) ;
create course(
c_id int primary key,
c_name varchar(20) not null,
c_score int check(c_score>=0 and c_score<=100),
c_time int check(c_time between 0 and 100));

如果是不会SQL语句呢,那我也不知道怎么做。
一看就知道LZ没仔细的看过SQL方面的书,这是最基本的建表语句。