Foreign Key 可以 References 两个 Fields 吗?

[复制链接]
查看11 | 回复3 | 2005-10-30 17:05:33 | 显示全部楼层 |阅读模式
建表如下成功:
create table t
(
yjxh number(3),
ejxh number(3),
ejmc varchar2(20),
constraint t_fk foreign key (yjxh, ejxh) references sample_ejbm (yjxh, ejxh)
);
但是对父表执行操作会出现以下错误:
SQL> update sample_ejbm set ejxh=2 where yjxh=3 and ejxh=1;
update sample_ejbm set ejxh=2 where yjxh=3 and ejxh=1
*
ERROR 位于第 1 行:
ORA-02292: 违反完整约束条件 (DH.T_FK) - 已找到子记录日志
是不是foreign key 不能有两个 fields?
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
SQL> create table t1(a int,b int,c int);
表已创建。
SQL> alter table t1 add constraint t1_pk primary key(a,b);
表已更改。
SQL> create table t2(a int,b int,c int);
表已创建。

SQL> alter table t1 add constraint t2_f foreign key(a,b) references t1(a,b);
表已更改。
SQL> insert into t1 values(1,2,3);
已创建 1 行。
SQL> insert into t2 values(1,2,4);
已创建 1 行。
SQL> commit;
提交完成。
SQL> update t1 set c=4 where a=1 and b=2;
已更新 1 行。
SQL> commit;
提交完成。

你的yjxh=3 and ejxh=1; 是不是不在同一行
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
主表中的主键再被另一表引用的时候,且有子记录时是不允许修改、删除该主键的
这是数据库完整性的一个要求。
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
谢谢!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行