Practicals File 2025
Practicals File 2025
1. C ONSIDER THE FOLLOWING MOVIE TABLE AND WRIT E THE SQL QUERIES BASED O N I T .
Answers:
a) select pow(5,3);
b) select round(563.854741,-2);
e)select right("Media",3);
3. S UPPOSE
Y OUR SCHOOL M ANAGEMENT HAS DECI DE D TO CONDUC T CRICKET MATCHES
BETWEEN STUDEN TS OF C LASS XI AND C LASS XII. S TUDENTS OF EACH CLASS ARE
ASKED TO JOI N ANY ON E OF THE FOUR T EAMS – T EAM T ITAN , T EAM R OCKERS , T EAM
M AGNET AND T EAM H URRICANE . D URING SUMMER VACATIONS , VARIOUS MATCHES
WILL BE CO NDUCT ED BET WEEN THESE T EAMS . H ELP YOUR SPORTS TEACHER TO DO
THE FOLLOWING :
a) Create a database “Sports”.
b) Create a table “TEAM” with following considerations:
a. It should have a column TeamID for storing an integer value between 1 to
9,which refers to unique identification of a team.
b. Each TeamID should have its associated name (TeamName), which should be a
string of length not less than 10 characters.
c. Using table level constraint, make TeamID as the primary key.
c) Show the structure of the table TEAM using a SQL statement.
d) As per the preferences of the students four teams were formed as given below.
Insertthese four rows in TEAM table:
a. Row 1: (1, Tehlka)
b. Row 2: (2, Toofan)
c. Row 3: (3, Aandhi)
d. Row 3: (4, Shailab)
e) Show the contents of the table TEAM using a DML statement.
f) Now create another table MATCH_DETAILS and insert data as shown below. Choose
appropriate data types and constraints for each attribute.
MatchI MatchDa FirstTeam SecondTea FirstTeamSc SecondTeamS
D te ID mID ore core
M1 2021/12/ 2 107 93
20
M3 2021/12/ 3 86 81
22
M4 2021/12/ 4 65 67
23
M5 2021/12/ 4 52 88
24
M6 2021/12/ 3 97 68
25
A NSWERS :
create table team -> (teamid int(1), -> teamnamevarchar(10), primary key(teamid));
c) desc team;
I NSERTING DATA :
mqsql> insert into team -> values(1,'Tehlka');
b) selectmatch_details.matchid,match_details.firstteamid,team.teamname,match_d
etails.firstteamscore from match_details, team where match_details.firstteamid=
team.teamid and match_details.firstteamscore>70;
c) mselect matchid, teamname, firstteamid, secondteamid,matchdate from
match_details, team where match_details.firstteamid = team.teamid;
def e_data():try:
while True:
rno=int(input("Enter student rollno="))name=input("Enter
student name=") c.execute("use {}".format('school'))
c.execute("insert into students
values({},'{}');".format(rno,name)) db.commit()
choice=input("Do you want to add more record<y/n>=")if choice in "Nn":
break
db=ms.connect(host="localhost",user="root",password="root") c=db.cursor()
while True:
print("MENU\n1. Create Database\n2. Drop Database \n3.
Create Table\n4. Insert Record \n5. Display Entire Data\n6.Exit")
choice=int(input("Enter your choice<1-6>="))if choice==1:
c_database()elif
choice==2:
d_database()elif
choice==3:
c_table() elif
choice==4:
e_data() elif
choice==5:
d_data() elif
choice==6:
break
else:
print(“Wrong option selected:”)
2. using mysqlconnector
import mysql.connector as ms db=ms.connect(host="localhost",user="root",passwd="root",datab
ase='school')
cn=db.cursor() def
insert_rec():
try:
while True:
rn=int(input("Enter roll number:"))sname=input("Enter
name:") marks=float(input("Enter marks:"))
gr=input("Enter grade:") cn.execute("insert into students
values({},'{}',{},'{}')".format(rn,sname,marks,gr)) db.commit()
ch=input("Want more records? Press (N/n) to stopentry:")
if ch in 'Nn':break
except Exception as e:
print("Error", e)
def
update_r
ec():try:
rn=int(input("Enter rollno to update:"))marks=float(input("Enter new
marks:")) gr=input("Enter Grade:")
cn.execute("update students set marks={},grade='{}'where
rno={}".format(marks,gr,rn))
db.commit() except
Exception as e:
print("Error",e)
def
delete_r
ec():try:
rn=int(input("Enter rollno to delete:"))cn.execute("delete from students
where
rno={}".format(rn))
db.commit() except
Exception as e:
print("Error",e)
def view_rec():try:
cn.execute("select * from students")
except Exception as e:
print("Error",e)
while True:
print("MENU\n1. Insert Record\n2. Update Record \n3. DeleteRecord\n4. Display Record
\n5. Exit")
ch=int(input("Enter your choice<1-4>="))if ch==1:
insert_rec()elif
ch==2:
update_rec()elif
ch==3:
delete_rec()elif
ch==4:
view_rec()elif
ch==5:
breakelse:
print("Wrong option selected")
O UTPUT :