This file looks large and may slow your browser down if we attempt
to syntax highlight it, so we're showing it without any
pretty colors.
Highlight
it anyway.
| 1 |
-- |
| 2 |
-- CRM DDL |
| 3 |
-- |
| 4 |
|
| 5 |
-- basic table definitions |
| 6 |
CREATE TABLE product ( |
| 7 |
id SERIAL, |
| 8 |
description VARCHAR(255), |
| 9 |
name VARCHAR(255) NOT NULL, |
| 10 |
price DOUBLE PRECISION NOT NULL |
| 11 |
); |
| 12 |
|
| 13 |
|
| 14 |
CREATE TABLE customer ( |
| 15 |
id serial, |
| 16 |
first_name VARCHAR(255) NOT NULL, |
| 17 |
last_name VARCHAR(255) NOT NULL |
| 18 |
); |
| 19 |
|
| 20 |
CREATE TABLE purchase ( |
| 21 |
id serial , |
| 22 |
total DOUBLE PRECISION NOT NULL, |
| 23 |
customer_id BIGINT NOT NULL |
| 24 |
); |
| 25 |
|
| 26 |
|
| 27 |
CREATE TABLE line_item ( |
| 28 |
id serial, |
| 29 |
product_id BIGINT NOT NULL, |
| 30 |
purchase_id BIGINT NOT NULL |
| 31 |
); |
| 32 |
|
| 33 |
-- sets up the foreign keys |
| 34 |
alter table line_item add foreign key (product_id) references product(id); |
| 35 |
|
| 36 |
alter table line_item add foreign key (purchase_id ) references purchase (id); |
| 37 |
|
| 38 |
alter table purchase add foreign key(customer_id ) references customer (id); |