Created
December 23, 2013 22:36
-
-
Save fweep/8106005 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 account ( | |
id SERIAL NOT NULL UNIQUE, | |
name TEXT NOT NULL | |
); | |
CREATE TABLE credit_card ( | |
id SERIAL NOT NULL UNIQUE, | |
account_id INTEGER NOT NULL REFERENCES account(id), | |
card_number TEXT NOT NULL, | |
UNIQUE (account_id, id) | |
); | |
CREATE TABLE address ( | |
id SERIAL NOT NULL UNIQUE, | |
account_id INTEGER NOT NULL REFERENCES account(id), | |
credit_card_id INTEGER NULL, | |
FOREIGN KEY (credit_card_id, account_id) REFERENCES credit_card(id, account_id) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment