-
-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathm.9.problem.1.sql
More file actions
87 lines (69 loc) · 2.29 KB
/
Copy pathm.9.problem.1.sql
File metadata and controls
87 lines (69 loc) · 2.29 KB
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
/*
A customer has a unique customer identifier, a name, a billing address (street, city, state, and zip),
and a collection of submitted work orders.
*/
CREATE TABLE Customer (
customerId CHAR(8) PRIMARY KEY,
name VARCHAR(45),
billAddress VARCHAR(45),
collectionId CHAR(8)
);
/**
A work order has a unique work order number, a creation date, a date required, a completion date, a customer, an optional supervising employee,
a work address (street, city, state, zip), and a set of tasks.
*/
CREATE TABLE WorkOrder (
orderId CHAR(8) PRIMARY KEY,
createDate DATE,
complDate DATE,
workAddress VARCHAR(45),
customerId CHAR(8) NOT NULL,
colTaskId CHAR(8) NOT NULL,
FOREIGN KEY (customerId) REFERENCES Customer (customerId)
);
/**
Each task has a unique task identifier, a task name, an hourly rate, and estimated hours.
Tasks are standardized across work orders so that the same task can be performed on many work orders.
*/
CREATE TABLE Task (
taskId CHAR(8) PRIMARY KEY,
name VARCHAR(45),
rate INT,
estHours INT
);
/**
Each task on a work order has a status (not started, in progress, or completed), actual hours, and a completion date.
The completion date is not entered until the status changes to complete.
*/
CREATE TABLE WorkTasksCollection (
wtId CHAR(8) PRIMARY KEY,
orderId CHAR(8) NOT NULL,
taskId CHAR(8) NOT NULL,
status SET('not started', 'in progress', 'completed'),
actualHours INT,
completionDate DATE,
FOREIGN KEY (orderId) REFERENCES WorkOrder (orderId),
FOREIGN KEY (taskId) REFERENCES Task (taskId)
);
/**
The data about materials include a unique material identifier, a name, and an estimated cost.
A material can appear on multiple work orders.
*/
CREATE TABLE Material (
mtId CHAR(8) PRIMARY KEY,
name VARCHAR(45),
cost INT
);
/**
Each work order uses a collection of materials. A material used on a work order includes
the estimated quantity of the material and the actual quantity of the material used.
*/
CREATE TABLE MaterialsCollection (
collId CHAR(8) PRIMARY KEY,
mtId CHAR(8) NOT NULL,
orderId CHAR(8) NOT NULL,
estQuantity INT,
actQuantity INT,
FOREIGN KEY (orderId) REFERENCES WorkOrder (orderId),
FOREIGN KEY (mtId) REFERENCES Material (mtId)
);