-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sql
130 lines (117 loc) · 6.39 KB
/
script.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
CREATE TABLE IF NOT EXISTS contact (
contact_id CHAR(10) NOT NULL PRIMARY KEY,
contact_description VARCHAR(20) NOT NULL,
street VARCHAR(50),
city VARCHAR(20),
state VARCHAR(20),
zipcode INT,
email VARCHAR(50),
phone CHAR(20)
);
CREATE TABLE IF NOT EXISTS consultant (
consultant_id CHAR(10) NOT NULL PRIMARY KEY,
first_name VARCHAR(20) NOT NULL,
last_name VARCHAR(20) NOT NULL,
contact_id CHAR(10) NOT NULL,
FOREIGN KEY (contact_id) REFERENCES contact (contact_id)
);
CREATE TABLE IF NOT EXISTS wedding (
wedding_id CHAR(10) NOT NULL PRIMARY KEY,
wedding_name VARCHAR NOT NULL,
contract_date DATE NOT NULL,
consultant_id INTEGER NOT NULL,
estimated_cost MONEY NOT NULL,
actual_cost MONEY,
FOREIGN KEY (consultant_id) REFERENCES consultant (consultant_id)
);
CREATE TABLE IF NOT EXISTS client (
client_id CHAR(10) NOT NULL PRIMARY KEY,
client_wedding_id CHAR(10) NOT NULL,
contact_id CHAR(10) NOT NULL,
first_name VARCHAR(20) NOT NULL,
last_name VARCHAR(20) NOT NULL,
FOREIGN KEY (client_wedding_id) REFERENCES client_wedding (client_wedding_id),
FOREIGN KEY (contact_id) REFERENCES contact (contact_id)
);
CREATE TABLE IF NOT EXISTS client_wedding (
client_wedding_id CHAR(10) NOT NULL PRIMARY KEY,
wedding_id CHAR(10) NOT NULL,
client_id CHAR(10) NOT NULL,
FOREIGN KEY (wedding_id) REFERENCES wedding (wedding_id),
FOREIGN KEY (client_id) REFERENCES client (client_id)
);
CREATE TABLE IF NOT EXISTS event (
event_id CHAR(10) NOT NULL PRIMARY KEY,
event_name VARCHAR NOT NULL,
event_type VARCHAR NOT NULL,
description VARCHAR NOT NULL,
beginning_date DATE NOT NULL,
beginning_time TIMESTAMP NOT NULL,
ending_date DATE NOT NULL,
ending_time TIMESTAMP NOT NULL,
wedding_id CHAR(10) NOT NULL,
loc_id CHAR(10),
FOREIGN KEY (wedding_id) REFERENCES wedding (wedding_id),
FOREIGN KEY (loc_id) REFERENCES location (loc_id)
);
CREATE TABLE IF NOT EXISTS location (
loc_id CHAR(10) NOT NULL PRIMARY KEY,
name VARCHAR NOT NULL,
type VARCHAR NOT NULL,
address VARCHAR NOT NULL
);
CREATE TABLE IF NOT EXISTS guest_attendance (
attendance_id CHAR(10) NOT NULL PRIMARY KEY,
event_id CHAR(10) NOT NULL,
first_name VARCHAR(20) NOT NULL,
last_name VARCHAR(20) NOT NULL,
is_invited BOOLEAN NOT NULL,
contact_id INTEGER NOT NULL,
FOREIGN KEY (event_id) REFERENCES event (event_id),
FOREIGN KEY (contact_id) REFERENCES contact (contact_id)
);
CREATE TABLE IF NOT EXISTS guest_invited (
invitation_id CHAR(10) NOT NULL PRIMARY KEY,
event_id CHAR(10) NOT NULL,
first_name VARCHAR(20) NOT NULL,
last_name VARCHAR(20) NOT NULL,
is_attended BOOLEAN,
contact_id INTEGER NOT NULL,
FOREIGN KEY (event_id) REFERENCES event (event_id),
FOREIGN KEY (contact_id) REFERENCES contact (contact_id)
);
CREATE TABLE IF NOT EXISTS service_selection (
selection_id CHAR(10) NOT NULL PRIMARY KEY,
service_id CHAR(10) NOT NULL,
event_id CHAR(10) NOT NULL,
estimated_cost MONEY NOT NULL,
actual_cost MONEY NOT NULL,
scheduled_date DATE NOT NULL,
actual_start_date DATE NOT NULL,
scheduled_contractor_id CHAR(10) NOT NULL,
actual_contractor_id CHAR(10) NOT NULL,
FOREIGN KEY (event_id) REFERENCES event (event_id),
FOREIGN KEY (service_id) REFERENCES service (service_id),
FOREIGN KEY (scheduled_contractor_id) REFERENCES contractor (contractor_id),
FOREIGN KEY (actual_contractor_id) REFERENCES contractor (contractor_id)
);
CREATE TABLE IF NOT EXISTS service (
service_id CHAR(3) NOT NULL PRIMARY KEY, /* Considering that the number of services is unlikely to exceed 999 */
name VARCHAR NOT NULL,
type VARCHAR NOT NULL,
description VARCHAR NOT NULL
);
CREATE TABLE IF NOT EXISTS service_contract (
service_contract_id CHAR(10) NOT NULL PRIMARY KEY,
detailed_service_description VARCHAR NOT NULL,
cost MONEY NOT NULL,
service_id CHAR(10) NOT NULL,
FOREIGN KEY (service_id) REFERENCES service (service_id),
FOREIGN KEY (contractor_id) REFERENCES contractor (contractor_id)
);
CREATE TABLE IF NOT EXISTS contractor (
contractor_id CHAR(10) NOT NULL PRIMARY KEY,
company_name VARCHAR NOT NULL,
contact_id CHAR(10) NOT NULL,
FOREIGN KEY (contact_id) REFERENCES contact (contact_id)
);