添加约束及联合主键

1、PLSQL为某个字段添加约束


--为表增加主键约束
alter table 表名
add constraints 约束名称(多个约束名称不能相同) primary key(添加约束的字段);

--添加唯一约束,tab_check_unique表示约束的名称
alter table tab_check
add constraints tab_check_unique unique(che_name);

--添加检查约束
alter table tab_check
add constraints tab_check_age check(che_age>18 and che_age<60);

--删除主键约束
alter table tab_check
drop constraints tab_check;

--禁用约束
alter table tab_check disable constraints tab_check;

--启用约束
alter table tab_check enable constraints tab_check;

为表添加外键约束:

alter table tab_stu
add constraints tab_stu foreign key(class_id) references tab_class(class_id);

--联合主键
create table tab_person(
 tab_firstname varchar2(10),
 tab_lastname varchar2(10),
 tab_gender varchar2(5),
 primary key(tab_firstname,tab_lastname)
);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值