db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Steele <programjste...@gmail.com>
Subject Constraint already exists in Schema 'APP'
Date Wed, 04 Apr 2012 21:27:02 GMT

I have three tables Person, Patient, and Employee. Both Patient and Employee
have a Foreign Key to Person; however, when creating the constraint for the
second time I get the following error: 

Constraint 'PERSON_FK' already exists in Schema 'APP'.

[code]
CREATE TABLE PERSON (
	PERSON_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1,
INCREMENT BY 1)
);

CREATE TABLE PATIENT (
	PATIENT_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1,
INCREMENT BY 1),
	PERSON_ID INTEGER NOT NULL
);
		
ALTER TABLE PATIENT 
	ADD CONSTRAINT PERSON_FK Foreign Key (
		PERSON_ID)
	REFERENCES PERSON (
		PERSON_ID);


CREATE TABLE EMPLOYEE (
	EMPLOYEE_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1,
INCREMENT BY 1),
	PERSON_ID INTEGER NOT NULL
);

ALTER TABLE EMPLOYEE
	ADD CONSTRAINT PERSON_FK Foreign Key (
		PERSON_ID)
	REFERENCES PERSON (
		PERSON_ID);
[/code]

What do you do in this situation? Do you only create on constraint and then
reference it when using it again? If so, how?

Thanks,
John Steele

-- 
View this message in context: http://old.nabble.com/Constraint-already-exists-in-Schema-%27APP%27-tp33564657p33564657.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Mime
View raw message