SQL脚本创建数据表,并给出主键,外键,唯一键,约束

create database stu

use stu

create table S
(
sno
char(6),
sname
char(10),
age
int,
sex
char(2),
constraint PK_S primary key (sno),
constraint CK_age check(age>=0 and age<=150)
)

create table C
(
cno
char(8),
cname
char(16),
credit
int,
constraint PK_C primary key (cno),
constraint CK_credit check (credit>=0)
)

create table SC ( sno char(6),
cno
char (8),
constraint PK_SC primary key (sno,cno), constraint FK_s foreign key (sno) references S(sno),
constraint FK_c foreign key (cno) references C(cno)
)

posted @ 2011-07-26 16:26  gwjtssy  阅读(827)  评论(0编辑  收藏  举报