Sunteți pe pagina 1din 7

Project Database

Part 2
M Ehsan Nissar Ch 140755
Ayesha Liaqat 161073
Zaheer Ahmed 161075
Sarosh Ahmed 160646

Relation Schema

EXAMPLE QUERIES

create database AthleteTrainingSolution;


use AthleteTrainingSolution;

/* Creating Tables */
CREATE TABLE Team (
ID VARCHAR(50) PRIMARY KEY,
NAME VARCHAR(30) NOT NULL,
LOCATION VARCHAR(50)
);

CREATE TABLE Coach (


ID VARCHAR(50) PRIMARY KEY,
TEAMID VARCHAR(50),
CONSTRAINT FK_Coach_Team FOREIGN KEY(TEAMID) REFERENCES TEAM(ID) ON DELETE
CASCADE,
EMAIL VARCHAR(50),
NAME VARCHAR(50)
);

CREATE Table DrillsCollection(


ID VARCHAR(50) PRIMARY KEY,
AGE INT,
WEIGHT FLOAT,
HEIGHT FLOAT,
PUSHUPS INT,
CHINUPS INT,
RUNNING FLOAT,
BENCHPRESS INT
);

CREATE TABLE Player (


ID VARCHAR(50) PRIMARY KEY,
TEAMID VARCHAR(50),
CONSTRAINT FK_Player_Team FOREIGN KEY(TEAMID) REFERENCES TEAM(ID) ON DELETE
CASCADE,
NAME VARCHAR(30) NOT NULL,
AGE INT,
WEIGHT FLOAT,
HEIGHT FLOAT,
DRILLCOLID VARCHAR(50),
CONSTRAINT FK_Player_DrillsCollection FOREIGN KEY(DRILLCOLID) References
DrillsCollection(ID) ON DELETE CASCADE
);

CREATE TABLE NewDrills(


PLAYERID VARCHAR(50),
CONSTRAINT FK_NewDrills_Player FOREIGN KEY(PLAYERID) REFERENCES Player(ID) ON
DELETE CASCADE,
PUSHUPS INT,
CHINUPS INT,
RUNNING FLOAT,
BENCHPRESS INT,
ID varchar(50) PRIMARY KEY
);

CREATE TABLE PerformedDrills(


PLAYERID VARCHAR(50),
CONSTRAINT FK_NewDrills_Player FOREIGN KEY(PLAYERID) REFERENCES Player(ID) ON
DELETE CASCADE,
PUSHUPS INT,
CHINUPS INT,
RUNNING FLOAT,
BENCHPRESS INT,
ID varchar(50) PRIMARY KEY
);

/*INSERTING RECORDS */
INSERT INTO Team VALUES ('TK12-3521-1234', 'Lahore Qalanders', 'Lahore'),
('TK13-3521-1235', 'Islamabad United',
'Islamabad'),
('TK14-3521-1236', 'Peshawar Zalmi',
'Peshawar'),
('TK15-3521-1237', 'Quetta Gladiators',
'Quetta'),
('TK16-3521-1238', 'Karachi KIngs', 'Karachi');

INSERT INTO Coach VALUES ('CK12-3521-1234', 'TK12-3521-1234', 'ehsannisar3@gmail.com',


'Wasim Akram'),
('CK13-3521-1235', 'TK13-3521-1235',
'usmanali@gmail.com', 'Mickey Arthur'),
('CK14-3521-1236', 'TK14-3521-1236',
'abdullah@gmail.com', 'Dean Jones'),
('CK15-3521-1237', 'TK15-3521-1237',
'harisfa@gmail.com', 'Aqib Javed'),
('CK16-3521-1238', 'TK16-3521-1238',
'mamoon@gmail.com', 'Mushtaq Ahmed');

INSERT INTO DrillsCollection VALUES ('DC12-3521-1218', 23, 69.89, 181.81, 30, 20, 5.50,
30),
('DC13-3521-1219', 24,
70.35, 180.81, 35, 20, 5.00, 28),
('DC14-3521-1220', 23,
71.81, 180.91, 28, 25, 6.00, 30),
('DC15-3521-1221', 24,
70.21, 179.9, 32, 20, 5.00, 27),
('DC16-3521-1222', 25,
69.98, 182.00, 33, 18, 5.00, 25);

INSERT INTO Player VALUES ('PK12-3521-1234', 'TK12-3521-1234', 'Ahsan', 23, 69.89,


181.81, 'DC12-3521-1218'),
('PK13-3521-1235', 'TK12-3521-1234', 'Talha',
24, 70.35, 180.81, 'DC13-3521-1219'),
('PK14-3521-1236', 'TK12-3521-1234', 'Arslan',
23, 71.81, 180.91, 'DC14-3521-1220'),
('PK15-3521-1237', 'TK12-3521-1234', 'Saad',
24, 70.21, 179.9, 'DC15-3521-1221'),
('PK16-3521-1238', 'TK12-3521-1234',
'Tanveer', 25, 69.98, 182.00, 'DC16-3521-1222'),

('PK17-3521-1239', 'TK13-3521-1235', 'Hamza',


23, 69.89, 181.81, 'DC12-3521-1218'),
('PK18-3521-1240', 'TK13-3521-1235', 'Inaam',
24, 70.35, 180.81, 'DC13-3521-1219'),
('PK19-3521-1241', 'TK13-3521-1235', 'Yousaf',
23, 71.81, 180.91, 'DC14-3521-1220'),
('PK20-3521-1242', 'TK13-3521-1235', 'Bilal',
24, 70.21, 179.9, 'DC15-3521-1221'),
('PK21-3521-1243', 'TK13-3521-1235',
'Zeeshan', 25, 69.98, 182.00, 'DC16-3521-1222'),

('PK22-3521-1244', 'TK14-3521-1236', 'Amjad',


23, 69.89, 181.81, 'DC12-3521-1218'),
('PK23-3521-1245', 'TK14-3521-1236', 'Ajmal',
24, 70.35, 180.81, 'DC13-3521-1219'),
('PK24-3521-1246', 'TK14-3521-1236',
'Murtaza', 23, 71.81, 180.91, 'DC14-3521-1220'),
('PK25-3521-1247', 'TK14-3521-1236', 'Adnan',
24, 70.21, 179.9, 'DC15-3521-1221'),
('PK26-3521-1248', 'TK14-3521-1236', 'Ali',
25, 69.98, 182.00, 'DC16-3521-1222'),

('PK27-3521-1249', 'TK15-3521-1237', 'Ahmed',


23, 69.89, 181.81, 'DC12-3521-1218'),
('PK28-3521-1250', 'TK15-3521-1237', 'Hassan',
24, 70.35, 180.81, 'DC13-3521-1219'),
('PK29-3521-1251', 'TK15-3521-1237', 'Zaheer',
23, 71.81, 180.91, 'DC14-3521-1220'),
('PK30-3521-1252', 'TK15-3521-1237', 'Umer',
24, 70.21, 179.9, 'DC15-3521-1221'),
('PK31-3521-1253', 'TK15-3521-1237',
'Ehtisham', 25, 69.98, 182.00, 'DC16-3521-1222'),

('PK32-3521-1254', 'TK16-3521-1238', 'Saqib',


23, 69.89, 181.81, 'DC12-3521-1218'),
('PK33-3521-1255', 'TK16-3521-1238',
'Huzaifa', 24, 70.35, 180.81, 'DC13-3521-1219'),
('PK34-3521-1256', 'TK16-3521-1238', 'Waile',
23, 71.81, 180.91, 'DC14-3521-1220'),
('PK35-3521-1257', 'TK16-3521-1238', 'Asad',
24, 70.21, 179.9, 'DC15-3521-1221'),
('PK36-3521-1258', 'TK16-3521-1238',
'Abubakar', 25, 69.98, 182.00, 'DC16-3521-1222');

INSERT INTO PerformedDrills VALUES ('PK12-3521-1234', 25, 15, 5.00, 28, 'PD12-3521-
1211'),
('PK13-3521-1235', 23, 16,
4.50, 29, 'PD13-3521-1212'),
('PK14-3521-1236', 24, 18,
6.50, 27, 'PD14-3521-1213'),
('PK15-3521-1237', 34, 19,
2.50, 20, 'PD15-3521-1214'),
('PK16-3521-1238', 21, 10,
3.50, 20, 'PD16-3521-1215'),

('PK17-3521-1239', 30, 20,


5.50, 30, 'PD17-3521-1216'),
('PK18-3521-1240', 35, 20,
5.00, 28, 'PD18-3521-1217'),
('PK19-3521-1241', 28, 25,
6.00, 30, 'PD19-3521-1218'),
('PK20-3521-1242', 22, 18,
1.50, 16, 'PD20-3521-1219'),
('PK21-3521-1243', 29, 12,
2.50, 17, 'PD21-3521-1220'),

('PK22-3521-1244', 21, 14,


3.50, 18, 'PD22-3521-1221'),
('PK23-3521-1245', 26, 15,
4.50, 19, 'PD23-3521-1222'),
('PK24-3521-1246', 18, 15,
5.50, 20, 'PD24-3521-1223'),
('PK25-3521-1247', 19, 14,
1.50, 21, 'PD25-3521-1224'),
('PK26-3521-1248', 20, 12,
2.50, 22, 'PD26-3521-1225'),

('PK27-3521-1249', 24, 10,


3.50, 23, 'PD27-3521-1226'),
('PK28-3521-1250', 21, 9, 4.50,
24, 'PD28-3521-1227'),
('PK29-3521-1251', 15, 8, 5.50,
25, 'PD29-3521-1228'),
('PK30-3521-1252', 16, 14,
4.50, 26, 'PD30-3521-1229'),
('PK31-3521-1253', 14, 15,
2.50, 27, 'PD31-3521-1230'),

('PK32-3521-1254', 30, 20,


5.50, 30, 'PD32-3521-1231'),
('PK33-3521-1255', 25, 16,
3.50, 28, 'PD33-3521-1232'),
('PK34-3521-1256', 28, 25,
6.00, 30, 'PD34-3521-1233'),
('PK35-3521-1257', 27, 14,
4.50, 20, 'PD35-3521-1234'),
('PK36-3521-1258', 29, 14,
2.50, 21, 'PD36-3521-1235');

INSERT INTO NewDrills VALUES ('PK12-3521-1234', 5, 5, 0.50, 2, 'ND11-3521-1211'),


('PK13-3521-1235', 12, 4, 0.50, 0,
'ND12-3521-1212'),
('PK14-3521-1236', 4, 7, 0.00, 3, 'ND13-
3521-1213'),
('PK15-3521-1237', 0, 1 , 2.50, 7,
'ND14-3521-1214'),
('PK16-3521-1238', 12, 8, 1.50, 5,
'ND15-3521-1215'),
('PK17-3521-1239', 0, 0, 0.00, 0, 'ND16-
3521-1216'),
('PK18-3521-1240', 0, 0, 0.00, 0, 'ND17-
3521-1217'),
('PK19-3521-1241', 0, 0, 0.00, 0, 'ND18-
3521-1218'),
('PK20-3521-1242', 10, 2, 3.50, 6,
'ND19-3521-1219'),
('PK21-3521-1243', 4, 6, 2.50, 8, 'ND20-
3521-1220'),
('PK22-3521-1244', 9, 6, 1.50, 12,
'ND21-3521-1221'),
('PK23-3521-1245', 11, 5, 0.50, 9,
'ND22-3521-1222'),
('PK24-3521-1246', 10, 10, 0.50, 5,
'ND23-3521-1223'),
('PK25-3521-1247', 13, 6, 3.50, 1,
'ND24-3521-1224'),
('PK26-3521-1248', 13, 6, 2.50, 3,
'ND25-3521-1225'),
('PK27-3521-1249', 6, 10, 2.00, 7,
'ND26-3521-1226'),
('PK28-3521-1250', 14, 11, 0.50, 4,
'ND27-3521-1227'),
('PK29-3521-1251', 13, 17, 0.50, 5,
'ND28-3521-1228'),
('PK30-3521-1252', 16, 6, 0.50, 1,
'ND29-3521-1229'),
('PK31-3521-1253', 20, 3, 2.50, 0,
'ND30-3521-1230'),
('PK32-3521-1254', 0, 0, 0.00, 0, 'ND31-
3521-1231'),
('PK33-3521-1255', 10, 4, 1.50, 0,
'ND32-3521-1232'),
('PK34-3521-1256', 0, 0, 0.00, 0, 'ND33-
3521-1233'),
('PK35-3521-1257', 5, 6, 0.50, 7, 'ND34-
3521-1234'),
('PK36-3521-1258', 4, 4, 2.50, 4, 'ND35-
3521-1235');

/* Dropping Tables */

/*1*/
DROP TABLE Coach;

/*2*/
DROP TABLE DrillsCollection;

/*3*/
DROP TABLE NewDrills;

/*4*/
DROP TABLE PerformedDrills;

/*5*/
DROP TABLE Player;

/*6*/
DROP TABLE Team;

/*Example Queries*/

/*1*/
SELECT * FROM Coach;

/*2*/
SELECT P.ID FROM Player P
JOIN DrillsCollection D ON P.DRILLCOLID = D.ID
WHERE P.DRILLCOLID = 'DC12-3521-1218';

/*3*/
SELECT D.ID FROM PerformedDrills D
JOIN Player P ON D.PLAYERID = P.ID
WHERE D.ID = 'PD12-3521-1211';

/*4*/
SELECT N.ID FROM NewDrills N
JOIN Player P ON N.PLAYERID = P.ID
WHERE N.ID = 'ND32-3521-1232';
/*5*/
SELECT C.ID, T.NAME FROM Coach C
JOIN Team T ON C.TEAMID = T.ID;

/*6*/
SELECT C.ID, T.NAME, P.NAME FROM Coach C
JOIN Team T ON C.TEAMID = T.ID
JOIN Player P ON T.ID = P.TEAMID;

/*7*/
SELECT C.ID, T.NAME, P.NAME, D.ID FROM Coach C
JOIN Team T ON C.TEAMID = T.ID
JOIN Player P ON T.ID = P.TEAMID
JOIN PerformedDrills D ON P.ID = D.PLAYERID

/*8*/
SELECT C.ID, T.NAME, P.NAME, D.ID FROM Coach C
JOIN Team T ON C.TEAMID = T.ID
JOIN Player P ON T.ID = P.TEAMID
JOIN NewDrills D ON P.ID = D.PLAYERID;

/*9*/
SELECT C.ID, T.NAME, P.NAME, D.ID, D.CHINUPS, D.BENCHPRESS, D.PUSHUPS, D.RUNNING FROM
Coach C
JOIN Team T ON C.TEAMID = T.ID
JOIN Player P ON T.ID = P.TEAMID
JOIN PerformedDrills D ON P.ID = D.PLAYERID

/*10*/
SELECT D.ID, P.NAME, P. TEAMID FROM DrillsCollection D
JOIN Player P ON D.ID = P.DRILLCOLID;