在Oracle中实现关系模型的错误
我需要在Oracle中创建此MER的帮助。特别是在FOTOS表中,因为我有此代码:
CREATE TABLE "FOTOS"
(
"ID_FOTO" INT NOT NULL ENABLE,
"ID_USU" INT NOT NULL ENABLE,
"FECHA" DATE NOT NULL ENABLE,
CONSTRAINT "FOTOS_PK"
PRIMARY KEY ("ID_FOTO") ENABLE,
CONSTRAINT "FOTOS_FK"
FOREIGN KEY ("ID_USU") REFERENCES "USUARIOS" ("ID_USU") ENABLE
)
但是我一直遇到此错误:
ORA-02270:此列列表
无匹配的唯一或主键
ID_USU无匹配的唯一或主键是USUARIOS中的两个主要键之一 usuarios table
I need help creating this MER in Oracle. Specifically in FOTOS table as I have this code:
CREATE TABLE "FOTOS"
(
"ID_FOTO" INT NOT NULL ENABLE,
"ID_USU" INT NOT NULL ENABLE,
"FECHA" DATE NOT NULL ENABLE,
CONSTRAINT "FOTOS_PK"
PRIMARY KEY ("ID_FOTO") ENABLE,
CONSTRAINT "FOTOS_FK"
FOREIGN KEY ("ID_USU") REFERENCES "USUARIOS" ("ID_USU") ENABLE
)
However I keep getting this error:
ORA-02270: no matching unique or primary key for this column-list
ID_USU is one of two primary keys in USUARIOS
USUARIOS TABLE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个表只有一个主键。它可以具有多个唯一的钥匙,但是您只能使其中一个主要键。
您错误地做的是创建一个复合主键。您希望ID是唯一的,并且名称是唯一的,但是您将ID和名称的组合做成了唯一的组合,因此可以在表中使用重复的ID和重复名称。
您拥有的:
您想要什么:
No. A table can have just one primary key. It can have more than one unique key, but you can only make one of them primary.
What you mistakenly did instead is create a composite primary key. You want the ID to be unique and the name to be unique, but instead you made the combination of ID and name unique, thus allowing duplicate IDs and duplicate names in the table.
What you have:
What you want instead:
外键必须匹配主/唯一键,它们为列引用列。由于“ usuarios”的主要键是列“ id_usu”和“ nomusu”,因此您需要两个列才能将fk从“ fotos”添加到“ usuarios”中,所以只需将“ nomusu”列添加到“ fotos”并写入:
Foreign keys have to match the primary/unique key they reference column for column. Since the primary key of "USUARIOS" are columns "ID_USU" and "NOMUSU" you need two columns to add FK from "FOTOS" to "USUARIOS", so just add "NOMUSU" column to "FOTOS" and write: