Unity复习之键的约束

欢迎大家来到我的博客http://unity.gopedu.com/home.php?mod=space&uid=3352&do=blog&view=me&from=space

给表添加键的约束

--增加一列

alter table teacher add age int null

alter table users add age int null

 

--更改列类型

alter table teacher alter column age varchar(3)

alter table users alter column age varchar(3)

 

--删除一列

alter table teacher drop column age

alter table users drop column age

 

--为teacher表添加主键约束

alter table teacher add constraint t_pk primary key(id)

 

--为teacher表的name添加唯一约束

alter table teacher add constraint t_un unique(name)

 

--为teacher表的sex添加默认约束

alter table teacher add constraint t_de default('男') for sex

insert into teacher(id,name) values(101,'aa')

 

--为teacher表的age添加检查约束

alter table teacher add constraint t_ch check(age>=15 and age<=40)

insert into teacher(id,name,age) values(102,'bb',50)

 

--为teacher和users表添加主外关联

alter table score add constraint t_fk foreign key(uid) references users(id)

 

insert into score(id,grade,uid) values(1,85,110)

 

--删除约束

alter table score drop constraint t_fk

请继续关注我的博客

http://unity.gopedu.com/home.php?mod=space&uid=3352&do=blog&view=me&from=space

更多精彩尽在http://www.gopedu.com/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值