Oracle添加外键约束

时间:2020-09-24 22:03:46   收藏:0   阅读:54

1.创建表时并创建外键约束

create table score(
scoreID int primary key,
stuID int ,
score int constraint ck_score check(score between 0 and 100),
courseName varchar2(20) not null,
constraint fk_stuId foreign key(stuID) references student(stuID)
);

2.表创建成功后再添加外键约束

--添加外检约束 :alter table 从表表名 add constraint 外键约束名称 foreign key(列名) references 主表名称(主键列名)
alter table score add constraint ck_stuID foreign key(stuID) references student(stuID);
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!