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

查看:2372
本文介绍了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.

我不知道如何解决它,或者找到类似的例子来建议一个解决方案。 / p>

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天全站免登陆