Created
June 8, 2011 14:26
-
-
Save blt/1014519 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE A ( | |
id SERIAL NOT NULL PRIMARY KEY | |
); | |
CREATE TABLE B ( | |
id SERIAL NOT NULL PRIMARY KEY | |
); | |
CREATE TABLE Parent ( | |
id SERIAL NOT NULL PRIMARY KEY, | |
aId INTEGER NOT NULL REFERENCES A (id), | |
bId INTEGER NOT NULL REFERENCES B (id), | |
UNIQUE(aId, bId) | |
); | |
CREATE TABLE Child ( | |
parentId INTEGER NOT NULL REFERENCES Parent (id), | |
createdOn TIMESTAMP NOT NULL | |
); | |
-- Is it possible to create a unique constraint on Child | |
-- such that for all rows in Child at most one references | |
-- a Parent having some value of aId? Stated another way | |
-- can I created a unique constraint so that the join of the | |
-- above tables will have no duplicate aId? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment