Created
January 31, 2017 08:09
-
-
Save Torxed/8f62d2735844a3c84f94af2f33f92dbf 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 cars; | |
DROP TABLE people; | |
CREATE TABLE people ( | |
id serial PRIMARY KEY, | |
fname varchar(80), | |
lname varchar(80), | |
address varchar(80), | |
postcode varchar(80), | |
city varchar(80), | |
phone varchar(80), | |
email varchar(80), | |
UNIQUE(phone) | |
); | |
CREATE TABLE cars ( | |
so_id int4 NOT NULL, | |
make varchar(80), | |
model varchar(80), | |
PRIMARY KEY (so_id), | |
FOREIGN KEY (so_id) REFERENCES people(id) | |
); | |
INSERT INTO PEOPLE (fname, lname, address, postcode, city, phone, email) VALUES ('Bo', 'Karlsson', 'Furuv. 8', '12388', 'Goteborg', '01055223', '[email protected]'); | |
INSERT INTO cars (so_id, make, model) VALUES ((SELECT id FROM people WHERE phone='01055223'), 'Ferarri', 'F40'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment