-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.sql
More file actions
31 lines (29 loc) · 911 Bytes
/
db.sql
File metadata and controls
31 lines (29 loc) · 911 Bytes
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
-- Create the 'user' table
CREATE TABLE IF NOT EXISTS user (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
phone TEXT
);
-- Create the 'appartments' table
CREATE TABLE IF NOT EXISTS appartments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
address TEXT NOT NULL,
floor_level TEXT CHECK (floor_level IN ('first', 'second', 'third')) NOT NULL,
number_of_bedrooms INTEGER,
number_of_bathrooms INTEGER,
does_have_garage BOOLEAN,
user_id INTEGER,
-- Foreign key constraint
FOREIGN KEY (user_id) REFERENCES user(id)
);
-- Create the 'rent_history' table
CREATE TABLE IF NOT EXISTS rent_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
from_date DATE NOT NULL,
to_date DATE NOT NULL,
price REAL,
appartment_id INTEGER,
-- Foreign key constraint
FOREIGN KEY (appartment_id) REFERENCES appartments(id)
);