Skip to content

Instantly share code, notes, and snippets.

@Aupajo
Last active August 9, 2017 00:13
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 Aupajo/77cca4bf95935531707f8c2282d2a4a9 to your computer and use it in GitHub Desktop.
Save Aupajo/77cca4bf95935531707f8c2282d2a4a9 to your computer and use it in GitHub Desktop.
CREATE TABLE pancakes (
/* The order number may be NULL - the kitchen has to eat, too! */
order_number integer UNIQUE,
/* Gotta have syrup */
maple_syrup_brand text NOT NULL,
/* Require order number and maple syrup to be unique */
CONSTRAINT order_syrup UNIQUE (order_number, maple_syrup_brand)
);
/* Regular customer orders */
INSERT INTO pancakes VALUES (1, 'O Canada');
INSERT INTO pancakes VALUES (2, 'Pure Vermont Maple Syrup');
INSERT INTO pancakes VALUES (3, 'O Canada');
/* Chef makes himself a snack. Notice that this doesn't trigger the constraint,
because NULLs are treated as unique. */
INSERT INTO pancakes VALUES (NULL, 'O Canada');
INSERT INTO pancakes VALUES (NULL, 'O Canada');
/* Whoops! We already made that order! */
INSERT INTO pancakes VALUES (2, 'Pure Vermont Maple Syrup');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment