Skip to content

Instantly share code, notes, and snippets.

@fweep
Created December 23, 2013 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fweep/8106005 to your computer and use it in GitHub Desktop.
Save fweep/8106005 to your computer and use it in GitHub Desktop.
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