一只会飞的白菜 2017-04-12 12:11 采纳率: 0%
浏览 496

关于在oracle 11G键外键,

我想一个表时连接2个外键
create table tb_lm(
lm_id number not null primary key,--类名的id
lm_name varchar2(20) not null,--类名的名字
lm_date date default sysdate --时间
)
--创建序列跟触发器
--序列
create sequence seq_tb_lm;

create trigger t_tb_lm
before insert
on tb_lm
for each row
begin
:new.lm_id:=seq_tb_lm.nextval;
end;
--插入数据
insert into tb_lm(lm_name)
select '首页' from dual union
select '图书' from dual union
select '百货' from dual union
select '数码' from dual union
select '品牌' from dual

select * from tb_lm

--创建小分类表名tb_xfl
create table tb_xfl(
xflid number not null ,
xfllmid number not null references tb_lm(lm_id),
xflname varchar2(20) not null,
xfldate date default sysdate
)
--创建序列和触发器
create sequence seq_tb_xfl;

create trigger t_tb_xfl
before insert
on tb_xfl
for each row
begin
:new.xflid:=seq_tb_xfl.nextval;
end;

select * from tb_xfl

update tb_xfl set xfllmid=2,xflname='以纯' where xflid=4;

--创建商品表
create table tb_goods(
gs_id number not null,
gs_name varchar2(200) not null,
gs_flm number references tb_xfl (xfllmid),
gs_img varchar2(100) not null,
gs_price number(8,2) not null,
gs_kucun number,
gs_date date default sysdate
)

--创建序列和触发器
create sequence seq_goods;

create trigger t_tb_goods
before insert
on tb_goods
for each row
begin
:new.gsid:=seq_goods.nextval;
end;
可是报错,求大神帮忙解决,急

  • 写回答

1条回答 默认 最新

  • 数据猴 2024-03-19 10:13
    关注

    外键需要关联父表的主键,你给tb_xfl的xflid 添加主键,再给tb_goods的gs_flm 字段添加tb_xfl的xflid 为外键

    评论

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格