Oracle添加外键约束

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);
posted @ 2020-09-24 14:49  还可入梦  阅读(4171)  评论(0编辑  收藏  举报