lsqlthw ex8 + combined "code.sql"

This commit is contained in:
Dan Buch 2014-03-09 18:54:14 -04:00
parent f12fbd7682
commit 5bac8f2d09
2 changed files with 61 additions and 2 deletions

59
lsqlthw-remnants/code.sql Normal file
View File

@ -0,0 +1,59 @@
DROP TABLE IF EXISTS pet;
DROP TABLE IF EXISTS person;
DROP TABLE IF EXISTS person_pet;
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
);
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);
INSERT INTO person_pet (person_id, pet_id) VALUES (0, 0);
INSERT INTO person_pet VALUES (0, 1);
SELECT * FROM person;
SELECT name, age FROM pet;
SELECT name, age FROM pet WHERE dead = 0;
SELECT * FROM person WHERE first_name != "Zed";
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";
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;

View File

@ -10,8 +10,8 @@ DELETE FROM pet WHERE id IN (
SELECT * FROM pet;
SELECT * FROM person_pet;
DELETE FROM person pet
WHERE pet id NOT IN (
DELETE FROM person_pet
WHERE pet_id NOT IN (
SELECT id FROM pet
);