SQL 错误:“名称已被现有约束使用"; [英] SQL error: "name already used by an existing constraint"

查看:19
本文介绍了SQL 错误:“名称已被现有约束使用";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一些表并设置外键,但我一直遇到外键问题.

I'm trying to create some tables and setup the foreign keys but I keep encountering problems with the foreign keys.

早些时候我创建了下表,它工作正常

Earlier on I created the below table and it works fine

CREATE TABLE inpatient
(PatientNo varchar(6) NOT NULL,
WardNo number(2),
BedNo number(3) NOT NULL,
OnWaitingList date, 
WardRequired varchar(25), 
ExpectStayInDays number(4), 
DatePlaced date, 
DateLeave date, 
ActualLeave date, 

constraint PatientFK foreign key (PatientNo)     references Patient (patientNo),

constraint bedFK foreign key (BedNo)     references Bed (bedNo));

注意在倒数第二行使用了 patientFK.

Notice the use of patientFK on 2nd last line.

然后我继续创建另一个表

then I went on to create another table

CREATE TABLE NOK
(PatientNo varchar(6)   NOT NULL,
NOKFullName   varchar(25), 
NOKRelationship   varchar(25), 
NOKTelephone   number(11), 
NOKStreetAddress   varchar(25), 
NOKSuburb   varchar(25), 
NOKState   char(2), 
NOKPostCode   number(4), 


constraint patientFK foreign key (PatientNo)
references Patient (patientNo));

我收到以下错误消息

错误报告:SQL 错误:ORA-02264:名称已被现有约束使用02264. 00000 - 名称已被现有约束使用"*原因:指定的约束名称必须是唯一的.*Action:为约束指定一个唯一的约束名称.

Error report: SQL Error: ORA-02264: name already used by an existing constraint 02264. 00000 - "name already used by an existing constraint" *Cause: The specified constraint name has to be unique. *Action: Specify a unique constraint name for the constraint.

我不知道如何解决它或找到可以提出解决方案的类似示例.

I have no idea how to resolve it or find similar examples that can suggest a solution.

推荐答案

约束的名称(在这种情况下是 PatientFK)在数据库中是唯一的.您已经使用过一次,所以当您再次尝试使用它时会收到一条错误消息.只需为您在 NOK 表上设置的约束指定一个不同的名称:

The name of the constraint (PatientFK in this case) as to be unique in the database. You've already used it once, so you're getting an error message wen you try and use it again. Just give the constraint you're setting up on your NOK table a different name:

也许:

constraint patientFK_nok foreign key (PatientNo)

这篇关于SQL 错误:“名称已被现有约束使用";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆