-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_store_schema.sql
171 lines (128 loc) · 4.17 KB
/
game_store_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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
-- Employee Table
CREATE TABLE Employee(
EmpID CHAR(5),
EmpPositionID CHAR(5),
EmpFName VARCHAR(20) NOT NULL,
EmpLName VARCHAR(20) NOT NULL,
EmpPhone CHAR(12) NOT NULL,
EmpDoB DATE NOT NULL,
EmpStartDate DATE NOT NULL,
EmpSalary CURRENCY NOT NULL,
CONSTRAINT PKEmployee PRIMARY KEY (EmpID),
CONSTRAINT FKEmployee_EmpPositionID FOREIGN KEY (EmpPositionID) REFERENCES EmployeePosition
);
-- Customer Table
CREATE TABLE IF NOT EXISTS Customer(
CusID CHAR(5),
CusFName VARCHAR(20) NOT NULL,
CusLName VARCHAR(20) NOT NULL,
CusGender CHAR(1),
CusDoB DATE,
CusEmail VARCHAR(20) NOT NULL,
CusPhone CHAR(12) NOT NULL,
CusStreet VARCHAR(50) NOT NULL,
CusCity VARCHAR(50) NOT NULL,
CusState CHAR(2) NOT NULL,
CusZipcode CHAR(5) NOT NULL,
CONSTRAINT PKCustomer PRIMARY KEY (CusID)
);
-- EmployeePosition Table
CREATE TABLE IF NOT EXISTS EmployeePosition(
EmpPositionID CHAR(5),
EmpTitle VARCHAR(20) NOT NULL,
PositionDesc VARCHAR(100) NOT NULL,
CONSTRAINT PKEmployeePosition PRIMARY KEY (EmpPositionID)
);
-- Schedule Table
CREATE TABLE IF NOT EXISTS Schedule(
SchedCode CHAR(5),
SchedDay CHAR(3) NOT NULL,
SchedTime TIME NOT NULL,
CONSTRAINT PKSchedule PRIMARY KEY (SchedCode)
);
-- EmployeeSchedule Table
CREATE TABLE IF NOT EXISTS EmployeeSchedule(
SchedCode CHAR(5),
EmpID CHAR(5),
WorkDate DATE NOT NULL,
CONSTRAINT PKEmployeeSchedule PRIMARY KEY (SchedCode, EmpID),
CONSTRAINT FKEmployeeSchedule_SchedCode FOREIGN KEY (SchedCode) REFERENCES Schedule,
CONSTRAINT FKEmployeeSchedule_EmpID FOREIGN KEY (EmpID) REFERENCES Employee
);
-- GamePlatform Table
CREATE TABLE GamePlatform(
PlatformID CHAR(1),
PlatformName VARCHAR(20) NOT NULL,
CONSTRAINT PKGamePlatform PRIMARY KEY (PlatformID)
);
-- Genre Table
CREATE TABLE IF NOT EXISTS Genre(
GenreID CHAR(2),
GenreName VARCHAR(20) NOT NULL,
GenreDesc VARCHAR(100) NOT NULL,
CONSTRAINT PKGenre PRIMARY KEY (GenreID)
);
-- Location Table
CREATE TABLE IF NOT EXISTS Location(
LocationCode CHAR(5),
LocationDesc VARCHAR(100),
CONSTRAINT PKLocation PRIMARY KEY (LocationCode)
);
--Product Table
CREATE TABLE IF NOT EXISTS Product(
ProdID CHAR(5),
ProdName VARCHAR(100) NOT NULL,
GenreID CHAR(2),
PlatformID CHAR(1),
ProdPrice DOUBLE PRECISION NOT NULL,
ProdDesc VARCHAR(100),
ProdPlayerNum CHAR(2),
ProdMemory CHAR(7) NOT NULL,
ProdReleaseDate DATE,
CONSTRAINT PKProduct PRIMARY KEY (ProdID),
CONSTRAINT FKProduct_GenreID FOREIGN KEY (GenreID) REFERENCES Genre,
CONSTRAINT FKProduct_PlatformID FOREIGN KEY (PlatformID) REFERENCES GamePlatform
);
-- Production Location Table
CREATE TABLE IF NOT EXISTS ProductLocation(
LocationCode CHAR(5),
ProdID CHAR(5),
CONSTRAINT PKProductLocation PRIMARY KEY
(LocationCode, ProdID),
CONSTRAINT FKProductLocation_LocationCode FOREIGN KEY (LocationCode) REFERENCES Location,
CONSTRAINT FKProductLocation_Location_ProdID FOREIGN KEY (ProdID) REFERENCES Product
);
-- Purchase Table
CREATE TABLE IF NOT EXISTS Purchase(
PurchaseID CHAR(5),
CusID CHAR(5) NOT NULL,
PurchaseDate DATE NOT NULL,
PurchaseTime TIME NOT NULL,
TotalAmount DOUBLE PRECISION NOT NULL,
CONSTRAINT PKINVOICE PRIMARY KEY (PurchaseID),
CONSTRAINT FKCustomer_CusID FOREIGN KEY(CusID) REFERENCES Customer
);
-- PurchaseLine Table
CREATE TABLE IF NOT EXISTS PurchaseLine(
PurchaseID CHAR(5),
ProdID CHAR(5),
LineQty SMALLINT NOT NULL,
LinePrice DOUBLE PRECISION NOT NULL,
CONSTRAINT PKPurchaseLine PRIMARY KEY
(PurchaseID, ProdID),
CONSTRAINT FKPurchaseLine_PurchaseID FOREIGN KEY (PurchaseID) REFERENCES Purchase,
CONSTRAINT FKPurchaseLine_ProdID FOREIGN KEY (ProdID) REFERENCES Product
);
-- Survey Table
CREATE TABLE IF NOT EXISTS Survey(
SurveyID CHAR(5),
PurchaseID CHAR(5),
EmpID CHAR(5),
SurveyDate DATE NOT NULL,
SurveyTime TIME NOT NULL,
SurveyRating DOUBLE PRECISION NOT NULL,
SurveyComment VARCHAR(100),
CONSTRAINT PKSurvey PRIMARY KEY (SurveyID),
CONSTRAINT FKSurvey_PurchaseID FOREIGN KEY (PurchaseID) REFERENCES Purchase,
CONSTRAINT FKSurvey_EmpID FOREIGN KEY (EmpID) REFERENCES Employee
);