oracle 建多个外键 怎么建的?

oracle 建多个外键 怎么建的?,第1张

create table House(

id integer primary key,

type_d integer not null,

user_id integer not null,

street_id integer not null,

title varchar2(50) not null, --标题

description clob , --类型

dates Date , --时间

price number , --价格

contact varchar2(10), -- 联系

foreign KEY(type_d) REFERENCES Type(id),

foreign KEY(user_id) REFERENCES Users(id),

foreign KEY(street_id) REFERENCES Street(id)

)

可以的,写段代码给你看

--创建主表userinfos,userid是这个表的主键

create table userinfos(userid int primary key not null, username varchar(20) not null)

--创建表scores,scid是这个scores表的主键

create table scores(scid int primary key not null, useridsc int not null,score int not null)

--建立主外键约束,使得成绩表里的useridsc这个列存放的学生编号,必须是userinfos表的userid列的值,也就是说,不允许还没有这个学生,就有了这个学生的成绩

alter table scores add constraint FK_scores_userinfos foreign key (useridsc) references userinfos(userid)

希望你能看懂


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11287804.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-15
下一篇2023-05-15

发表评论

登录后才能评论

评论列表(0条)

    保存