-
Notifications
You must be signed in to change notification settings - Fork 42
/
schema.sql
104 lines (95 loc) · 3.04 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
Author: Mrin
Model : NorthWind
**/
DROP SCHEMA IF EXISTS northwind;
CREATE SCHEMA northwind;
USE northwind;
/* Table: customers */
CREATE TABLE customers (
id INT NOT NULL,
last_name VARCHAR(50) ,
first_name VARCHAR(50) ,
email VARCHAR(50) ,
company VARCHAR(50) ,
phone VARCHAR(25) ,
address1 VARCHAR(150),
address2 VARCHAR(150),
city VARCHAR(50) ,
state VARCHAR(50) ,
postal_code VARCHAR(15) ,
country VARCHAR(50) ,
PRIMARY KEY (id)
);
/* Table: employees */
CREATE TABLE employees (
id INT NOT NULL,
last_name VARCHAR(50) ,
first_name VARCHAR(50) ,
email VARCHAR(50) ,
avatar VARCHAR(250) ,
job_title VARCHAR(50) ,
department VARCHAR(50) ,
manager_id INT ,
phone VARCHAR(25) ,
address1 VARCHAR(150),
address2 VARCHAR(150),
city VARCHAR(50) ,
state VARCHAR(50) ,
postal_code VARCHAR(15) ,
country VARCHAR(50) ,
PRIMARY KEY (id)
);
/* Table: orders */
CREATE TABLE orders (
id INT NOT NULL,
employee_id INT ,
customer_id INT ,
order_date DATETIME ,
shipped_date DATETIME ,
ship_name VARCHAR(50) ,
ship_address1 VARCHAR(150) ,
ship_address2 VARCHAR(150) ,
ship_city VARCHAR(50) ,
ship_state VARCHAR(50) ,
ship_postal_code VARCHAR(50) ,
ship_country VARCHAR(50) ,
shipping_fee DECIMAL(19,4) NULL DEFAULT '0.0000',
payment_type VARCHAR(50) ,
paid_date DATETIME ,
order_status VARCHAR(25),
PRIMARY KEY (id)
);
/* Table: order_details */
CREATE TABLE order_details (
order_id INT NOT NULL,
product_id INT ,
quantity DECIMAL(18,4) NOT NULL DEFAULT '0.0000',
unit_price DECIMAL(19,4) NULL DEFAULT '0.0000',
discount DOUBLE NOT NULL DEFAULT '0',
order_detail_status VARCHAR(25),
date_allocated DATETIME ,
PRIMARY KEY (order_id, product_id)
);
/* Table: products */
CREATE TABLE products (
id INT NOT NULL,
product_code VARCHAR(25) ,
product_name VARCHAR(50) ,
description VARCHAR(250),
standard_cost DECIMAL(19,4) NULL DEFAULT '0.0000',
list_price DECIMAL(19,4) NOT NULL DEFAULT '0.0000',
target_level INT ,
reorder_level INT ,
minimum_reorder_quantity INT ,
quantity_per_unit VARCHAR(50) ,
discontinued TINYINT NOT NULL DEFAULT '0',
category VARCHAR(50),
PRIMARY KEY (id)
);
/* Foreign Key: orders */
ALTER TABLE orders ADD CONSTRAINT fk_orders__customers FOREIGN KEY (customer_id) REFERENCES customers(id);
ALTER TABLE orders ADD CONSTRAINT fk_orders__employees FOREIGN KEY (employee_id) REFERENCES employees(id);
/* Foreign Key: order_details */
ALTER TABLE order_details ADD CONSTRAINT fk_order_details__orders FOREIGN KEY (order_id) REFERENCES orders(id);
ALTER TABLE order_details ADD CONSTRAINT fk_order_details__products FOREIGN KEY (product_id) REFERENCES products(id);