创建一个实例
令有一个c表c(cno,……)
create table student
(
sno int,
cno int,
ID char(100),
sname char(100),
sage int,
ssex char(50),
class char(50),
grade char(20),
score int,
steacher char(50),
tel char(100)
)
1 为student添加主键
alter table student add constraint PK_sno primary key(sno)
2 为student添加唯一性约束
alter table student add constraint UQ_I D unique(ID)
3 为student添加默认约束
alter table student add constraint DF_ssex default('男')for ssex
4 为student添加check约束
alter table student add constraint CK_sage check(sage between 10and 50)
alter table student add constraint CK_ssex check(ssex='男'orsex='女')
5 为student添加外键约束
alter table student add constraint FK_cno foreign key(cno)references c(cno)
删除时 alter table student drop 约束列(如 CK_sage)
易沙:http://yiyisha