oracle约束

----test用户
--1 创建表
--1)学员表
create table stuInfo
(
sid number,
sname varchar2(20),
sage number,
sbirth date,
gradeid number
)
--2)年级表
create table gradeInfo
(
gid number,
gname varchar2(10)
)

--2 添加约束
--1)主键约束
alter table stuInfo --从表/子表(引用)
add constraint PK_sid primary key(sid);

alter table Gradeinfo --主表(被用)
add constraint PK_gid primary key(gid);
--2)外键约束
alter table stuInfo
add constraint FK_gradeid foreign key(gradeid)
references Gradeinfo(Gid);
--3)非空约束
alter table stuInfo
modify sname not null;
--4)默认约束
alter table stuInfo
modify sage default 18;
--5)检查约束
alter table stuInfo
add constraint CK_sage check(sage between 15 and 30);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值