1.PRIMARY KEY约束 USE test GO CREATE TABLE student (sutdent_number int PRIMARY KEY, student_name char(30)) GO 2 FOREIGN KEY约束 例如,下面就是一个使用FOREIGN KEY约束的例子: CREATE TABLE product (product_number int, student_number int FOREIGN KEY REFERENCES student(student_number) ON DELETE NO ACTION) GO 3 UNIQUE约束 例如,下面的SQL语句创建了一个test2表,其中指定了c1字段不能包含重复的值: USE test GO CREATE TABLE test2 (c1 int UNIQUE, c2 int) GO INSERT test2 VALUES(1,100) GO 如果再插入一行: INSERT test2 VALUES(1,200) 4 CHECK约束 例如,下面的SQL语句创建一个成绩(score)表,其中使用CHECK约束来限定成绩只能在0~100分之间: CREATE TABLE score (sutdent_number int, score int NOT NULL CHECK(score>=0 AND score
USE test
GO
CREATE TABLE student
(sutdent_number int PRIMARY KEY,
student_name char(30))
GO
2 FOREIGN KEY约束
例如,下面就是一个使用FOREIGN KEY约束的例子:
CREATE TABLE product
(product_number int,
student_number int
FOREIGN KEY REFERENCES student(student_number)
ON DELETE NO ACTION)
GO
3 UNIQUE约束
例如,下面的SQL语句创建了一个test2表,其中指定了c1字段不能包含重复的值:
USE test
GO
CREATE TABLE test2
(c1 int UNIQUE,
c2 int)
GO
INSERT test2 VALUES(1,100)
GO
如果再插入一行:
INSERT test2 VALUES(1,200)
4 CHECK约束
例如,下面的SQL语句创建一个成绩(score)表,其中使用CHECK约束来限定成绩只能在0~100分之间:
CREATE TABLE score
(sutdent_number int,
score int NOT NULL CHECK(score>=0 AND score