Last active
August 9, 2017 00:13
-
-
Save Aupajo/77cca4bf95935531707f8c2282d2a4a9 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 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