SQL server设置取值范围的问题

来源:百度知道 编辑:UC知道 时间:2024/06/03 22:49:12
我现在建立了一个学生信息数据库 里面有下面几个表
学生(学号,年龄,性别,系号)
课程(课号,课名,学分,学时)
选课(学号,课号,成绩)
现在怎么设置年龄、学分、学时的取值范围啊 学校一点SQL语言基础都没教就让我们用SQL server做这个
课程(课号,课名,学分,学时)
这个表里有两个需要设置取值范围应该怎么写呢 好像把两个取值范围直接写上去不好使啊 中间是不是还要加什分号之类的东西隔开?

check约束
两个取值范围之间用 and 连接

范例
create table 课程(
课号 char(12),
课名 varchar(16),
学分 int check(学分>0 and 学分 <100),
学时 int check(学时>2 and 学时<4))

已测试 ok

check约束。

比如说年龄为Age

Check就要这么写,
age>0 and age<100
右键,Check,添加,右边表达式里写age>0 and age<100

--像这样做
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));