From 920c85be6a27c2d8209488d313d722a17d8cbddf Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sun, 9 Mar 2014 15:36:18 -0400 Subject: [PATCH] lsqlthw ex7 extra credit --- lsqlthw-remnants/ex7-ec.sql | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 lsqlthw-remnants/ex7-ec.sql diff --git a/lsqlthw-remnants/ex7-ec.sql b/lsqlthw-remnants/ex7-ec.sql new file mode 100644 index 0000000..e5ec770 --- /dev/null +++ b/lsqlthw-remnants/ex7-ec.sql @@ -0,0 +1,71 @@ +DROP TABLE pet; +DROP TABLE person; +DROP TABLE person_pet; + +-- ex2.sql + +CREATE TABLE person ( + id INTEGER PRIMARY KEY, + first_name TEXT, + last_name TEXT, + age INTEGER +); + +CREATE TABLE pet ( + id INTEGER PRIMARY KEY, + name TEXT, + breed TEXT, + age INTEGER, + dead INTEGER +); + +CREATE TABLE person_pet ( + person_id INTEGER, + pet_id INTEGER +); + +-- ex3.sql + +INSERT INTO person (id, first_name, last_name, age) + VALUES (0, "Zed", "Shaw", 37); + +INSERT INTO pet (id, name, breed, age, dead) + VALUES (0, "Fluffy", "Unicorn", 1000, 0); + +INSERT INTO pet VALUES (1, "Gigantor", "Robot", 1, 1); + +-- ex4.sql + +INSERT INTO person_pet (person_id, pet_id) VALUES (0, 0); +INSERT INTO person_pet VALUES (0, 1); + +-- ex5.sql + +SELECT * FROM person; + +SELECT name, age FROM pet; + +SELECT name, age FROM pet WHERE dead = 0; + +SELECT * FROM person WHERE first_name != "Zed"; + +-- ex6.sql + +SELECT pet.id, pet.name, pet.age, pet.dead + FROM pet, person_pet, person + WHERE + pet.id = person_pet.pet_id AND + person_pet.person_id = person.id AND + person.first_name = "Zed"; + +-- ex7.sql + +SELECT name, age FROM pet WHERE dead = 1; + +DELETE FROM pet WHERE dead = 1; + +SELECT * FROM pet; + +INSERT INTO pet VALUES (1, "Gigantor", "Robot", 1, 0); + +SELECT * FROM pet;