-
Notifications
You must be signed in to change notification settings - Fork 923
/
Copy pathschema.sql
33 lines (30 loc) · 872 Bytes
/
schema.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
\c dogfight
CREATE TABLE clients
(
id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
account_limit INTEGER NOT NULL,
balance INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE transactions
(
id SERIAL PRIMARY KEY,
client_id INTEGER NOT NULL,
value INTEGER NOT NULL,
operation CHAR(1) NOT NULL,
description VARCHAR(10) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
CONSTRAINT fk_transactions_client_id
FOREIGN KEY (client_id) REFERENCES clients (id)
);
DO
$$
BEGIN
INSERT INTO clients (id, name, account_limit)
VALUES (1, 'Rocky Balboa', 100000),
(2, 'Apollo Creed', 80000),
(3, 'Mike Tyson', 1000000),
(4, 'John Jones', 10000000),
(5, 'Muhammad Ali', 500000);
END;
$$