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);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM