You are on page 1of 8

Design a database management system for a

sports tournament taking place at different


venues all over India.

Each participant has a unique id (pid) using which it


can register for a sport with unique identities(sid)
taking place at different venues all over India. Each
venue also has a unique identity (vid). Each sport
has different registration prices and prizes for the
winners.

E-R Diagram
Relational Schema

Connecting to python

import mysql.connector
mydb = mysql.connector.connect(
host = 'localhost',
user = 'root',
password = '123456',
database = 'dbproject'
)
Creating Tables

t1 = ‘’’CREATE TABLE sport(


sid int PRIMARY KEY,
sname varchar(25),
reg_price int,
prize int
);’’’

t2 = ‘’’CREATE TABLE venue(


vid int PRIMARY KEY,
city varchar(25),
state varchar(25),
date date,
timeslot time
);’’’
t3 = ‘’’CREATE TABLE participant(
pid int PRIMARY KEY,
pname varchar(25),
age int,
height int,
weight int,
sid int,
vid int,
FOREIGN KEY (sid) REFERENCES sport(sid) on DELETE
CASCADE,
FOREIGN KEY (vid) REFERENCES venue(vid) on DELETE
CASCADE
);’’’
cur.execute(t1)
cur.execute(t2)
cur.execute(t3)
Entering data in the tables

INSERT INTO venue VALUES (1, "New Delhi", "Delhi", "2022-12-11"


,"4:00");
INSERT INTO venue VALUES (2, "Mumbai", "Maharashtra",
"2022-12-13", "3:00");
INSERT INTO venue VALUES (3, "Kolkata", "West Bengal",
"2022-12-12", "5:00");
INSERT INTO venue VALUES (4, "Chennai", "Tamil Nadu",
"2022-12-10" ,"4:00");
INSERT INTO venue VALUES (5, "Chandigarh", "Punjab",
"2022-12-15", "4:00");

INSERT INTO sport VALUES (1,"Football",100,10000);


INSERT INTO sport VALUES (2,"Cricket",150,20000);
INSERT INTO sport VALUES (3,"Athletics",100,15000);
INSERT INTO sport VALUES (4,"Shooting",200,30000);
INSERT INTO sport VALUES (5,"Hockey",150,25000);

INSERT INTO participant VALUES (1,"Ram",19,175,65,3,1);


INSERT INTO participant VALUES (2,"Vijay",21,183,65,1,2);
INSERT INTO participant VALUES (3,"Sagar",22,185,65,4,2);
INSERT INTO participant VALUES (4,"Naman",18,177,65,3,4);
INSERT INTO participant VALUES (5,"Ajay",25,179,65,2,1);
INSERT INTO participant VALUES (6,"Sahil",24,186,65,1,3);
INSERT INTO participant VALUES (7,"Shyam",20,181,65,5,3);
INSERT INTO participant VALUES (8,"Aman",21,183,65,2,5);
Tables-

Participant

Sport
Venue

1) Participants in New Delhi

SELECT participant.pid, participant.pname FROM participant


WHERE vid = 1;

2) Participants who participate in Football in


Kolkata

SELECT participant.pid, participant.pname FROM participant


WHERE sid = 1 AND vid = 3;

3) Participants whose heights are between 170


and 180 cm

SELECT participant.pid, participant.pname FROM participant


WHERE height > 170 AND height < 180;

Relational Algebra

You might also like