约束


--非空约束 not null

--主键约束(PK) primary key constraint 唯一且不为空

	alter table Student 
	add constraint PK_Student primary key(sId)


--唯一约束 (UQ)unique constraint 唯一,允许为空,但只能出现一次

alter table Student
add constraint UQ_Student_sNo unique(sNo)

--默认约束 (DF)default constraint 默认值

alter table Student
add constraint DF_Student_sSex default('男') for sSex


--检查约束 (CK)check constraint 范围以及格式限制

alter table Student
add constraint CK_Student_sSex check (sSex='男' or sSex='女')

alter table Student
add constraint CK_Student_sAge check (sAge >=20)

alter table Student
add constraint CK_Student_date check (sIntime>sBirthday)


--外键约束 (FK)foreign key constraint 表关系

alter table Student
drop constraint FK_Student_sClassId

alter table Student
add constraint FK_Student_sClassId foreign key (sClassId) references Class(cId)
--删除约束

alter table Student
drop constraint CK_Student_sAge











··

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值