Last active
July 25, 2017 16:04
-
-
Save Shurlow/37e82b7cdf47e71d861e796a3224de6e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| DROP TABLE IF EXISTS pets CASCADE; | |
| DROP TABLE IF EXISTS owners CASCADE; | |
| DROP TABLE IF EXISTS pets_owners; | |
| CREATE TABLE pets ( | |
| id serial PRIMARY KEY, | |
| name varchar(255), | |
| age integer, | |
| kind text | |
| ); | |
| CREATE TABLE owners ( | |
| id serial PRIMARY KEY, | |
| name text, | |
| is_alergic boolean | |
| ); | |
| CREATE TABLE pets_owners ( | |
| id serial PRIMARY KEY, | |
| pet_id integer NOT NULL REFERENCES pets ON DELETE CASCADE, | |
| owner_id integer NOT NULL REFERENCES owners ON DELETE CASCADE, | |
| role text | |
| ); | |
| INSERT INTO pets (name, age, kind) | |
| VALUES ('Chucky', 102, 'goat'); | |
| INSERT INTO pets (name, age, kind) | |
| VALUES ('Brenda', 5, 'salmon'); | |
| INSERT INTO pets (name, age, kind) | |
| VALUES ('Art', 22, 'giraffe'); | |
| INSERT INTO owners (name, is_alergic) | |
| VALUES ('Kathy', false); | |
| INSERT INTO owners (name, is_alergic) | |
| VALUES ('Glen', true); | |
| INSERT INTO pets_owners (pet_id, owner_id, role) | |
| VALUES (2, 1, 'Best Friend') | |
| INSERT INTO pets_owners (pet_id, owner_id, role) | |
| VALUES (1, 1, 'Father') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment