SQL error: “name already used by an existing const

2019-03-07 01:34发布

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));

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));

and I get the following error message

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.

1条回答
ら.Afraid
2楼-- · 2019-03-07 02:28

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:

Perhaps:

constraint patientFK_nok foreign key (PatientNo)
查看更多
登录 后发表回答