-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_db.sql
50 lines (40 loc) · 1.29 KB
/
import_db.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
CREATE TABLE users (
id INTEGER PRIMARY KEY,
fname VARCHAR NOT NULL,
lname VARCHAR NOT NULL
);
CREATE TABLE questions (
id INTEGER PRIMARY KEY,
title VARCHAR,
body VARCHAR NOT NULL,
user_id INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE question_follows (
id INTEGER PRIMARY KEY,
user_id INTEGER,
question_id INTEGER,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (question_id) REFERENCES questions(id)
);
CREATE TABLE replies (
id INTEGER PRIMARY KEY,
question_id INTEGER NOT NULL,
parent_reply INTEGER,
user_id INTEGER NOT NULL,
body VARCHAR NOT NULL,
FOREIGN KEY (parent_reply) REFERENCES replies(id),
FOREIGN KEY (question_id) REFERENCES questions(id),
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE question_likes (
id INTEGER PRIMARY KEY,
user_id INTEGER,
question_id INTEGER,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (question_id) REFERENCES questions(id)
);
INSERT INTO users (fname, lname) VALUES ('Alex', 'Bullen');
INSERT INTO users (fname, lname) VALUES ('Sam', 'Faber Manning');
INSERT INTO questions (title, body, user_id) VALUES ('Help!', "I'm stuck on sequel!", 1);
INSERT INTO questions (title, body, user_id) VALUES ('Need review...', "Can someone look over my code?", 2);