forked from dan-balan/CS50-finance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
19 lines (16 loc) · 778 Bytes
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-- Initalize the database
-- Drop any existing data and create empty tables.
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS trades;
CREATE TABLE users (id INTEGER, username TEXT NOT NULL, hash TEXT NOT NULL, cash NUMERIC NOT NULL DEFAULT 10000.00, PRIMARY KEY(id));
CREATE UNIQUE INDEX username ON users (username);
CREATE TABLE trades (
id INTEGER NOT NULL,
transaction_id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
name TEXT NOT NULL,
shares INTEGER NOT NULL,
price NUMERIC NOT NULL,
transacted TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(id) REFERENCES users(id)
);