-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.sql
30 lines (25 loc) · 841 Bytes
/
data.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
\c biztime
DROP TABLE IF EXISTS invoices;
DROP TABLE IF EXISTS companies;
CREATE TABLE companies (
code text PRIMARY KEY,
name text NOT NULL UNIQUE,
description text
);
CREATE TABLE invoices (
id serial PRIMARY KEY,
comp_code text NOT NULL REFERENCES companies ON DELETE CASCADE,
amt float NOT NULL,
paid boolean DEFAULT false NOT NULL,
add_date date DEFAULT CURRENT_DATE NOT NULL,
paid_date date,
CONSTRAINT invoices_amt_check CHECK ((amt > (0)::double precision))
);
INSERT INTO companies
VALUES ('apple', 'Apple Computer', 'Maker of OSX.'),
('ibm', 'IBM', 'Big blue.');
INSERT INTO invoices (comp_Code, amt, paid, paid_date)
VALUES ('apple', 100, false, null),
('apple', 200, false, null),
('apple', 300, true, '2018-01-01'),
('ibm', 400, false, null);