-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQL Code.txt
298 lines (232 loc) · 5.76 KB
/
SQL Code.txt
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
CREATE TABLE players
(
playerID int(10),
first_name varchar(20) NOT NULL,
middle_name varchar(20),
last_name varchar(20),
father_name varchar(20),
mother_name varchar(20),
present_locationID int(10) NOT NULL,
permanent_locationID int(10) NOT NULL,
clubID int(10) NOT NULL,
PRIMARY KEY (playerID)
);
ALTER TABLE players
ADD membership varchar(20);
ALTER TABLE players
ADD date_of_birth date;
ALTER TABLE players
MODIFY COLUMN playerID int(10) UNSIGNED AUTO_INCREMENT;
CREATE TABLE clubs
(
clubID int(10),
club_name varchar(30) NOT NULL,
president varchar(30),
date_established date,
PRIMARY KEY (clubID)
);
ALTER TABLE clubs
ADD COLUMN club_locationID int(10) NOT NULL;
ALTER TABLE clubs
MODIFY COLUMN clubID int(10) UNSIGNED AUTO_INCREMENT;
CREATE TABLE player_history
(
playerID int(10),
club_name varchar(30) NOT NULL,
transferred_to varchar(30),
transferred_from varchar(30),
total_runs int(7) NOT NULL,
total_wickets int(5) NOT NULL,
team_leader boolean,
PRIMARY KEY (playerID)
);
ALTER TABLE player_history
MODIFY COLUMN team_leader char;
ALTER TABLE player_history
ADD INDEX(playerID);
CREATE TABLE education
(
playerID int(10) NOT NULL,
degree varchar(20) NOT NULL,
institution varchar(30) NOT NULL,
department varchar(30) NOT NULL,
result varchar (10),
year int(4),
PRIMARY KEY (playerID)
);
ALTER TABLE education
DROP PRIMARY KEY;
ALTER TABLE education
ADD INDEX(playerID);
CREATE TABLE locations
(
locationID int(10),
house varchar(5),
street varchar(20),
postCode varchar(10),
thana varchar(20) NOT NULL,
district varchar(20) NOT NULL,
PRIMARY KEY (locationID)
);
CREATE TABLE matches
(
matchID int(15),
date_of_match date,
team_batting_first varchar(30),
team_bowling_first varchar(30),
home_team varchar(30) NOT NULL,
away_team varchar(30) NOT NULL,
PRIMARY KEY (matchID)
);
ALTER TABLE matches
ADD COLUMN man_of_the_match varchar(30),
ALTER TABLE matches
ADD COLUMN umpire varchar(30),
ALTER TABLE matches
ADD COLUMN venueID int(5);
ALTER TABLE events_organised
DROP home_team;
ALTER TABLE events_organised
DROP away_team;
CREATE TABLE venues
(
venueID int(10) NOT NULL,
capacity int(7),
city varchar(20) NOT NULL,
PRIMARY KEY (venueID)
);
DROP TABLE venues;
CREATE TABLE contracts
(
playerID int(10),
clubID int(10),
contract_start_date date NOT NULL,
contract_end_date date NOT NULL,
total_fee float(15) NOT NULL,
due_date date NOT NULL,
actual_payment_date date NOT NULL,
amount_paid date NOT NULL,
paymentID int(20),
PRIMARY KEY (playerID, clubID, paymentID)
);
ALTER TABLE contracts
ADD COLUMN witness1 varchar(50) NOT NULL,
ADD COLUMN witness2 varchar(50),
ADD COLUMN designation varchar(30) NOT NULL,
ADD COLUMN authorized_person varchar(100) NOT NULL,
ADD COLUMN contract_amount numeric(12, 2) NOT NULL;
ALTER TABLE contracts
DROP total_fee;
ALTER TABLE contracts
DROP PRIMARY KEY;
ALTER TABLE contracts
ADD PRIMARY KEY (paymentID);
ALTER TABLE contracts
DROP due_date;
ALTER TABLE contracts
DROP actual_payment_date;
ALTER TABLE contracts
DROP amount_paid;
ALTER TABLE players
ADD COLUMN membershipID int(10);
ALTER TABLE contracts
MODIFY COLUMN paymentID int(20) UNSIGNED AUTO_INCREMENT;
CREATE TABLE payment_scedule
(
paymentID int(20),
due_date date NOT NULL,
actual_payment_date date NOT NULL,
amount_paid numeric (12, 2) NOT NULL,
);
ALTER TABLE payment_scedule
ADD COLUMN payment_serial int(30);
ALTER TABLE payment_scedule
RENAME TO payment_schedule;
CREATE TABLE best_performers
(
playerID int(10),
matchID int(10),
team_for varchar(30) NOT NULL,
team_against varchar(30) NOT NULL,
runs int(7) NOT NULL,
wickets int(5) NOT NULL,
PRIMARY KEY (playerID, matchID)
);
ALTER TABLE best_performers
RENAME TO match_performance;
ALTER TABLE match_performance
DROP team_for;
ALTER TABLE match_performance
DROP team_against;
ALTER TABLE match_performance
CHANGE runs total_runs INT(7) NOT NULL;
ALTER TABLE match_performance
CHANGE wickets total_wickets INT(7) NOT NULL;
ALTER TABLE match_performance
ADD COLUMN outstanding_performance varchar(30);
ALTER TABLE match_performance
DROP PRIMARY KEY;
CREATE TABLE events_organised
(
eventID int(10),
clubID int(10),
matchID int(10),
PRIMARY KEY (eventID, clubID, matchID)
);
ALTER TABLE events_organised
DROP matchID;
ALTER TABLE events_organised
DROP clubID;
ALTER TABLE events_organised
ADD COLUMN start_date,
ADD COLUMN end_date,
ADD COLUMN eventName varchar(40);
CREATE TABLE personal_best
(
playerID int(10),
eventID int(10),
matchID int(10),
club_name varchar(30) NOT NULL,
club_against varchar(30) NOT NULL,
runs int(7) NOT NULL,
wickets int(5) NOT NULL,
PRIMARY KEY (playerID, eventID, matchID)
);
ALTER TABLE personal_best
DROP PRIMARY KEY;
ALTER TABLE personal_best
ADD INDEX(playerID);
CREATE TABLE teams
(
clubID int(10) NOT NULL,
formation_date date,
eventID int(10) NOT NULL,
team_leaderID int(10) NOT NULL,
coachID int(10) NOT NULL,
coach_name varchar(50) NOT NULL,
teamID int(10),
PRIMARY KEY (teamID)
);
CREATE TABLE team_playerlist
(
teamID int(10) NOT NULL,
playerID int(10) NOT NULL,
player_name varchar(100)
);
ALTER TABLE team_playerlist
ADD INDEX(teamID);
ALTER TABLE teams
MODIFY COLUMN teamID int(10) UNSIGNED AUTO_INCREMENT;
CREATE TABLE membership_details
(
membershipID int(10) NOT NULL,
Membership_name varchar(30) NOT NULL,
membership_type varchar(20),
Regi_date date,
exp_date date,
PRIMARY KEY (membershipID)
);
ALTER TABLE players
DROP COLUMN membership;
ALTER TABLE membership_details
ADD COLUMN playerID int(10);