-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sql
More file actions
35 lines (30 loc) · 818 Bytes
/
Copy pathinit.sql
File metadata and controls
35 lines (30 loc) · 818 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
32
33
34
35
CREATE DATABASE expense;
\c expense postgres;
CREATE TABLE users(
user_id SERIAL PRIMARY KEY,
user_name VARCHAR(255),
password TEXT
);
CREATE TABLE expense(
expense_id SERIAL PRIMARY KEY,
user_id INT,
expense VARCHAR(255),
FOREIGN KEY(user_id) REFERENCES users(user_id)
);
CREATE TABLE users_expense(
amount_id SERIAL PRIMARY KEY,
expense_id INT,
user_id INT,
amount DECIMAL,
entry_date Date NOT NULL DEFAULT CURRENT_DATE,
entry_time TIME NOT NULL DEFAULT CURRENT_TIME,
FOREIGN KEY(expense_id) REFERENCES expense(expense_id),
FOREIGN KEY(user_id) REFERENCES users(user_id)
);
CREATE TABLE plans(
plan_id INT,
expense_id INT,
amount DECIMAL,
FOREIGN KEY(expense_id) REFERENCES expense(expense_id),
PRIMARY KEY(plan_id, expense_id)
);