2 -- Create a very simple database to hold lists information
4 PRAGMA foreign_keys = ON;
7 id INTEGER PRIMARY KEY,
17 id INTEGER PRIMARY KEY,
20 FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE
23 create table list_items (
24 id INTEGER PRIMARY KEY,
25 product_quantity INTEGER,
28 FOREIGN KEY (product_id) REFERENCES products(id) ON UPDATE CASCADE,
29 FOREIGN KEY (list_id) REFERENCES lists(id) ON UPDATE CASCADE
32 create table products (
33 id INTEGER PRIMARY KEY,
36 cost REAL --XXX rename to price $
40 -- Write two users, one of them (#1) has a list that contains
41 -- 4kg potatoes cost $5
43 insert into users values (NULL, 'user1','user1','user1@localhost',
45 insert into users values (NULL, 'user2','user2','user2@localhost',
47 insert into users values (NULL, 'user3','user3','user3@localhost',
49 insert into lists values (NULL, 1, "A first list");
50 insert into products values(NULL, 'potatoes', 4, 5);
51 insert into list_items values (NULL, 1, 1,1); -- insert 1 product #1 into list 1
53 ALTER TABLE lists ADD created TIMESTAMP;
54 ALTER TABLE lists ADD updated TIMESTAMP;
55 UPDATE lists SET created = DATETIME('NOW'), updated = DATETIME('NOW');