0% found this document useful (0 votes)
15 views

SQL 2018 Practical Removed Down

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

SQL 2018 Practical Removed Down

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Program No- 19

Sql queries based on table


1. Consider the following MOVIE table and write the SQL queries based on it.

Movie_ID MovieName Type ReleaseDate ProductionCost BusinessCost


M001 The Kashmir Files Action 2022/01/26 1245000 1300000
M002 Attack Action 2022/01/28 1120000 1250000
M003 Looop Lapeta Thriller 2022/02/01 250000 300000
M004 Badhai Do Drama 2022/02/04 720000 68000
M005 Shabaash Mithu Biography 2022/02/04 1000000 800000
M006 Gehraiyaan Romance 2022/02/11 150000 120000

a) Display all information from movie.


b) Display the type of movies.
c) Display movieid, moviename, total_eraning by showing the business done by the movies. Claculate the
business done by movie using the sum of productioncost and businesscost.
d) Display movieid, moviename and productioncost for all movies with productioncost greater thatn 150000 and
less than 1000000.
e) Display the movie of type action and romance.
f) Display the list of movies which are going to release in February, 2022.
Answers:
a) select * from movie;

b) select distinct type from movie;

c) select movie_id, moviename, productioncost from movie where productioncost >150000 and
productioncost <1000000;
d.) select movieid, moviename, productioncost + businesscost "total earning" from movie;

e.) select moviename from movie where type ='action' or type='romance';

f.) select moviename from moview where releasedate=2022;


Program No- 20
Create Database with DDL and DML command
Create a database students and perform all command of sql including DDl & DML operation
a) Create a database “students”.
b) Create a table “student” with following considerations:
c) Using table level constraint, make roll no as the primary key.
d) Show the structure of the table Student using a SQL statement.
e) As per the preferences of the students four teams were formed as given below. Insert records in Student table
e) Show the contents of the table Student 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.

admno Name Class Section Roll No Address


1234 Aditi Sharma 9 A 4 SJE
2605 Shreya Nagpal 10 D 7 Jor bagh
3712 Tanya verma 11 C 15 Malviya Nagar
5612 Krish Gupta 12 B 15 Janakpuri
6523 Zayn malik 11 E 40 Rohini
4031 Shivani mehta 9 A 33 hauzKhas

1. Command for creating a database.

2. Command for using thedatabase.

3. Command for creating atable.

4. Command for showing the structure of table.


5. Command to show tables present in database.

6. Command for inserting data into atable.

7. .Command to view the contents of the table.

8. Command to retrieve data.

9. For using DISTINCT command


10. Command for using WHEREclause.

11. Command for using ORDER BYclause.

12. Command for using UPDATE.

13. Command for using ALTER (to modify structure oftable).

14. Command for using LIKEoperator.

15. Command for using aggregatefunctions.


16. Command for using GROUPBY

17. Command for using HAVINGclause

18. Command for using Group by with orderby.

19. Command for using group by and having clause with whereclause.

20. Command for equi-join oftables


21. Command to retrieve data from twotables.

22. Command to delete table

23. Command for using group by clause in join.

24. Command for using where clause and group by

25. Command for adding primarykey


26. Command to delete a column

27. Command to remove primary key.

28. Command to increase marks


Program No- 21
Creating DATBASE with two tables

Suppose your school management has decided to conduct cricket matches between students of Class XI
and Class XII. Students of each class are asked to join any one of the four teams – Team Titan, Team
Rockers, Team Magnet and Team Hurricane. During summer vacations, various matches will be
conducted between these teams. Help your sports teacher to do the following:
a) Create a database “Sports”.
b) Create a table “TEAM” with following considerations:
c. It should have a column TeamID for storing an integer value between 1 to 9, which refers to
unique identification of a team.
d. Each TeamID should have its associated name (TeamName), which should be a string of
length not less than 10 characters.
e. Using table level constraint, make TeamID as the primary key.
f) Show the structure of the table TEAM using a SQL statement.
g) As per the preferences of the students four teams were formed as given below. Insert these
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.
MatchID MatchDate FirstTeamID SecondTeamID FirstTeamScore SecondTeamScore
M1 2021/12/20 1 2 107 93
M2 2021/12/21 3 4 156 158
M3 2021/12/22 1 3 86 81
M4 2021/12/23 2 4 65 67
M5 2021/12/24 1 4 52 88
M6 2021/12/25 2 3 97 68

a) create database sports;

b) Creating table with the given specification


create table team -> (teamid int(1), -> teamname varchar(10), primary key(teamid));

c) desc team;
d) Inserting data:
mqsql> insert into team -> values(1,'Tehlka');
mqsql> insert into team -> values(2,'Toofan');
mqsql> insert into team -> values(3,'Aandhi');
mqsql> insert into team -> values(4,'shailab');

e) Creating another table:


create table match_details
-> (matchid varchar(2) primary key,
-> matchdate date,
-> firstteamid int(1) references team(teamid),
-> secondteamid int(1) references team(teamid),
-> firstteamscore int(3),
-> secondteamscore int(3));
Program No- 22
Mysql queries based on two tables
Write following queries:
a) Display the matchid, teamid, teamscore whoscored more than 70 in first ining along with team name.
b) Display matchid, teamname and secondteamscore between 100 to 160.
c) Display matchid, teamnames along with matchdates.
d) Display unique team names
Answers:
a) Select match_details.matchid,match_details.firstteamid,team.teamname,match_details.firstteamscore
from match_details, team where match_details.firstteamid = team.teamid and match_details.first

b) Selectmatch_details.matchid,match_details.firstteamid,team.teamname,match_details.firstteamsco
re from match_details, team where match_details.firstteamid = team.teamid and
match_details.firstteamscore>70;

c) select matchid, teamname, firstteamid, secondteamid, matchdate from match_details, team


where match_details.firstteamid = team.teamid;

d) select distinct(teamname) from match_details, team where match_details.firstteamid =


team.teamid;
Program No- 23
Write a MySQL connectivity based program
Write a MySQL connectivity program in Python to
• Create a database school
• Create a table students with the specifications - ROLLNO integer, STNAME character(10) in MySQL and
perform the following operations: o Insert two records in it
1. Display the contents of the table
2. Perform all the operations with reference to table ‘students’ through MySQL-Python connectivity.

import mysql.connector as ms
db=ms.connect(host="localhost",user="root",passwd="root",database='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 stop entry:")
if ch in 'Nn':
break
except Exception as e:
print("Error", e)
def update_rec():
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_rec():
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. Delete Record\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:
break
else:
print("Wrong option selected")

OUTPUT

You might also like