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

MySQL Practical File

Uploaded by

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

MySQL Practical File

Uploaded by

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

MySQL

PRACTICAL FILE

EFFORTS MADE BY:


VISHESH AGGARWAL
XII-A
HILLWOODS ACADEMY
14610368
COMPUTER SCIENCE PRACTICAL FILE

INDEX
S. No. AIM

STACK QUESTIONS
1. Write a menu-driven python program to implement stack operation

2. Write a program to implement a stack for the employee details (empno, name).

3. Write a menu driven program to push, pop and display bookno

SINGLE TABLE QUESTIONS


1. Create the relation EMPL and write commands for following queries.
2. Create the relation Club and write commands for following queries.
3. Create the relation Movie and write commands for following queries.
4. Create the relation Student and write commands for following queries.

5. Create the relation Cars and write commands for following queries.
6. Create the relation Library and write commands for following queries.
7. Create the relation Gym and write commands for following queries.
8. Create the relation Sports and write commands for following queries.
9. Create the relation Stationery and write commands for following queries.
10. Create the relation Supplier and write commands for following queries.
DOUBLE TABLE QUESTIONS
1. Consider the following tables BOOKS and ISSUED and write commands for each query.

2. Write SQL queries on the basis of tables WORKER and DEPT.


3. Write SQL queries on the basis of tables PLAYER and GAMES
4. Answer the queries on the basis of the tables TRADERS and ITEMS.
5. Write SQL queries of the following TRIP and TRANSPORT tables.
6. Consider the following CUSTOMER and COMPANY tables. Write SQL queries.
CONNECTIVITY QUESTIONS
1. Create a database School and perform following operations.
2. Create a table Electronics and insert records into the table

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

STACKS
PROGRAMS

(1) Write a menu-driven python program to implement stack operation.


def check_stack_isEmpty(stk):
if stk==[]:
return True
else:
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

return False
s=[]
top = None
def main_menu():
while True:
print("Stack Implementation")
print("1 - Push")
print("2 - Pop")
print("3 - Peek")
print("4 - Display")
print("5 - Exit")
ch = int(input("Enter the your choice:"))
if ch==1:
el = int(input("Enter the value to push an element:"))
push(s,el)
elif ch==2:
e=pop_stack(s)
if e=="UnderFlow":
print("Stack is underflow!")
else:
print("Element popped:",e)
elif ch==3:
e=pop_stack(s)
if e=="UnderFlow":
print("Stack is underflow!")
else:
print("The element on top is:",e)
elif ch==4:
display(s)
elif ch==5:
break
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

else:
print("Sorry, You have entered invalid option")
def push(stk,e):
stk.append(e)
top = len(stk)-1
def display(stk):
if check_stack_isEmpty(stk):
print("Stack is Empty")
else:
top = len(stk)-1
print(stk[top],"-Top")
for i in range(top-1,-1,-1):
print(stk[i])
def pop_stack(stk):
if check_stack_isEmpty(stk):
return "UnderFlow"
else:
e = stk.pop()
if len(stk)==0:
top = None
else:
top = len(stk)-1
return e
def peek(stk):
if check_stack_isEmpty(stk):
return "UnderFlow"
else:
top = len(stk)-1
return stk[top]

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

OUTP

(2) Write a program to implement a stack for the


employee details (empno, name).

stk=[]

top=-1

def line():
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

print('~'*100)

def isEmpty():

global stk

if stk==[]:

print("Stack is empty!!!")

else:

None

def push():

global stk

global top

empno=int(input("Enter the employee number to push:"))

ename=input("Enter the employee name to push:")

stk.append([empno,ename])

top=len(stk)-1

def display():

global stk

global top

if top==-1:

isEmpty()

else:

top=len(stk)-1

print(stk[top],"<-top")

for i in range(top-1,-1,-1):

print(stk[i])

def pop_ele():

global stk

global top

if top==-1:

isEmpty()
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

else:

stk.pop()

top=top-1

def main():

while True:

line()

print("1. Push")

print("2. Pop")

print("3. Display")

print("4. Exit")

ch=int(input("Enter your choice:"))

if ch==1:nm

push()

print("Element Pushed")

elif ch==2:

pop_ele()

elif ch==3:

display()

else:

print("Invalid Choice")

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

OUTPUT

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(3) Write a menu driven program to push, pop and display bookno.

l=[]
while True :
print('1.Push')
print('2.Pop')
print('3.Display')
ch=int(input('Enter choice'))
if ch==1:
a=int(input('Enter book no.'))
l.append(a)
if ch==2:
print(l.pop())
if ch==3:
for i in range(len(l)-1,-1,-1):
print('top',l[i],end=' ',sep='->')
OUTPUT

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

SINGLE TABLE
QUESTIONS

TABLE 1
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

(1) Create table empl as follows:

Sol.

(2) Insert record into it.

(3) WAQ to display name and salary of employees having salary greater than or equal to 700.

(4) WAQ to display name and salary of those employees who are not having salary in range of 700-
900.

(5) WAQ to display name of those employees whose name starts with ‘S’ and ends with ‘H’.

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(6) WAQ to display name, hiring date of those employees who are hired in 1990.

(7) WAQ to change the commission of Anya to 150.

(8) Predict the output


select ename from empl where name like ‘%A%’;

(9) Predict the output


select*from empl order by ename;

(10) Predict the output


select distinct job from empl;

TABLE 2
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

(1) WAQ to display thr record of male coach teaching swimming.

(2) WAQ to give primary key constraint to Coach_id

(3) WAQ to increase 500 rs in pay of women due to women empowermen

(4) WAQ to display the name of sports played in club

(5) WAQ to display the record of coaches having a in their name.

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(6) WAQ to delete the record of coach Kush as he has resigned.

(7) Predict the output


select min(Age) from club where sex=’F’;

(8) Predict the output


select avg(Pay) from club where sports=’Karate’;

(9) Predict the output


select count(distinct sports) from club;

(10) Predict the output


select sum(Pay)from club where DOA>’1998-01-31’;

TABLE 3
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

(1) Sumita like drama and scifi films. WAQ to find movies of her choice.

(2) WAQ to sort the movie by length of its name in descending order.

(3) WAQ to display a list of all movies with price over 20 and sorted by price.

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(4) Ram’s budget is Rs.54 and Cruise is his favourite actor. WAQ to display the movies he can watch

(5) WAQ to display records where rating is PG

(6) WAQ to display a report listing the movie name, current value and replacement value for each
movie. Calculate the replacement value as:
QTY*Price*1.15

(7) Predict the output


select * from mov where rating=’R’ or rating=’PG’

(8) Predict the output


VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

select * from mov where title like ‘C%’;

(9) Predict the output


update move set qty=4 where SNo=6;

(10) Predict the output


select title, round(price) as Price from mov;

TABLE 4

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(1) WAQ to select all the nonmedical students from table student.

(2) WAQ to list the names of those students who are in class 12 sorted by Stipend.

(3) WAQ to list all students sorted by AvgMarks in descending order.

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(4) WAQ to display a report listing Name,Stipend, Stream and amount of stipend received in a year
assuming that the stipend is paid every month.

(5) WAQ to display the record of students who belong to commerce stream and avgmarks>70

(6) Class 11th students have helped people during the


Pandemic. WAQ to award 5 marks to them.

(7) Predict the output


select count(name) from student;

(8) Predict the output


VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

select * from student where name like '%a';

(9) Predict the output


alter table student drop phone_no int ;

(10) Predict the output


select distinct stream from student;

TABLE 5
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

(1) WAQ to create the above table

(2) Insert records into the table

(3) Samanth wants to buy a car having insurance not more than 1 lakh and wants a new car model
starting from year 2015. Suggest him suitable cars.

(4) WAQ to check how many times letter e appears in the table.

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(5) The Tata company has change some interior parts of car Nexon due to which its insurance rate
has increase by 54,000. WAQ to make the new changes

(6) There was sudden boost in sales due to which Honda Amaze become out of stock. WAQ to
delete that car.

\
(7) Predict the output
select count('e') from cars;

(8) Predict the output


select * from cars where Insurance between 130000 and 324000;

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(9) Predict the output


select distinct colour from cars ;

(10) Predict the output


Alter table cars modify code int primary key ;

TABLE 6
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

(1) Create the above table.

(2) Insert records into the table.

(3) Shreya has interest in learning programming languages . WAQ to suggest her some books.

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(4) WAQ to display the the average price of the DBMS and OS books.

(5) Sunshine institute has a query of available books published by McGraw and BPB. Help them by
providing it.

(6) Due to the pandemic, ZPress Publications has to bear a huge loss due to which they were bound
to close their Publication. WAQ to delete the books published by ZPress.

(7) Predict the output


VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

select * from library where price between 100 and


200 ;

(8) Predict the output


select sum(QTY) from library ;

(9) Predict the output


alter table library modify Author varchar(10) default('Anonymous');

(10) Predict the output


select * from library where Title like 'D%' ;

TABLE 7
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

(1) Create the above table.

(2) Insert all the values and show the table.

(3) Display the names of product whose price is less than 25000.

(4) Display the details of product whose price is between 20000 and 30000.
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

(5) Increase the price of all the products by 10% and display the new table.

(6) Display the names of product whose manufacturer is Avon Fitness and arrange in descending
order.

(7) Predict the output


select from gym where manufacturer like 'A%';

(8) Predict the output

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

select distinct manufacturer from gym ;

(9) Predict the output


insert into gym values('P106', "Punching Bag,27500, "Workout Fastrack');

(10) Predict the output


delete from gym where manufacturer-'Avon Fitness' ;

TABLE 8
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

(1) Create the above table .

(2) Insert and display the records.

(3) Display the names of the students who have grade 'C' in either Game1 or Game2 or both.

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(4) Display the games taken up by the students, whose name starts with 'A'.

(5) Display the details of the in descending order of name.

(6) Create a new column Marks.

(7) Predict the output


update sports set marks 200 where Grade= 'A' or Grade= 'B' or Grade2= 'A' or Grade2='B';
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

(8) Predict the output


select from sports where gamel='cricket' or game2='cricket and grade='a';

(9) Predict the output


update sports set class=8 where name='Venna';

(10) Predict the output


alter table sports change name StudentName varchar(10) ;

TABLE 9
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

(1) Create the above table

(2) Insert the records and display it.

(3) WAQ to display the details of classic items in the table.

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(4) WAQ to display the details of items having the quantity greater than 30 and less than 80.

(5) WAQ to display item name whose price or quantity as 10

(6) WAQ to increase the prize of pens by rs.2

(7) Predict the output.


select count('e') from stationery ;

(8) Predict the output


update stationery set quantity=80 where Scode='I06';

(9) Predict the output


delete from stationery where items='stapler pins';

(10) Predict the output


alter table stationery change Items ItemName varchar(30);

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

Table 10

(1) Create the above table

(2) Insert the records and display it.

(3) WAQ to display the details of products of Nestle or Kissan.

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(4) WAQ to display the name and supplier of Kolkata

(5) WAQ to display the name that start with letter ‘C’.

(6)

(7) WAQ to display the details of products having price greater than 15 but less than 70.

(8) Predict the output.


select max (qty), min (qty) from supplier ;

(9) Predict the output


select distinct city from supplier;

(10) Predict the output


update supplier set price=28 where pname='Jam’;

(11) Predict the output


alter table supplier add Description varchar(50) ;

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

DOUBLE TABLE
QUESTIONS

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

DOUBLE TABLE 1

(1) Create the above two tables and linkage between them.

(2) Insert records into it.

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(3) WAQ to display the name of books and their quantity issued.

(4) WAQ to display the no. of books left after getting issued.

(5) WAQ to display the no. of books published by each publisher

(6) WAQ to display the name of books issued.

(7) Predict the output


select max(price) from books where Qty>18 ;

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(8) Predict the output


select bookname,count(*) from books where bookname like '%e%' group by bookname;

(9) Predict the output


select distinct Type from books;

(10) Predict the output


alter table issued modify QuantityIssued int default(0);

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

DOUBLE TABLE 2

(1) Create the above two tables

(2) Insert records into it

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(3) WAQ to display the records of female workers.

(4) WAQ to display name, department of the worker and the city to which they belong

(5) WAQ to display the name and DOB of those worker who belong to metropolitan cities

(6) WAQ to display the record of oldest person in the company.

(7) Predict the output


select * from dept where department like 'M%' ;

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(8) Predict the output


select * from worker order by salary desc ;

(9) Predict the output


select distinct city from dept ;

(10) Predict the output


alter table worker add Phoneno int ;

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

DOUBLE TABLE 3

(1) Create the above two tables

(2) Insert records into it

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(3) WAQ to display the names of player and the games they will play.

(4) WAQ to display the records of the first game to be played

(5) WAQ to display the name of players winning prize more than 8,000.

(6) Jatin’s is not well as he is suffering from Corona.The management has decided to replace him
with Samaksh Jain. WAQ to execute the above situation

(7) Predict the output


select sum(PrizeMoney) as TotalPrizeMoney from games

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(8) Predict the output


select * from player order by name ;

(9) Predict the output


select * from games where gamename like 'c%' ;

(10) Predict the output


select p.pcode, g.number from player p, games g where p.gcode=g.gcode order by p.pcode ;

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

DOUBLE TABLE 4

(1) Create the above two tables

(2) Insert records into it

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(3) WAQ to display the amount of purchase of each trader

(4) WAQ to display the the records of the name of items containing ‘12’.

(5) WAQ to display the names of items and the city to which they are to be transported

(6) Disp House Inc reported that 20 LED screens were found cracked due to damage in
transportation.
WAQ to deduct the quantity purchased.

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(7) Predict the output


select * from items where price>9000 order by company ;

(8) Predict the output


select tname, length(tname) as LengthofName from traders;

(9) Predict the output


select tcode, count(*) from items group by tcode;

(10) Predict the output


select max(price) as MaxPrice, min(price) as MinPrice from items ;

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

DOUBLE TABLE 5

(1) Create the above two tables

(2) Insert records into it

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(3) To display no, name, tdate from the table TRIP in asscending order of no.

(4) To display the name of the drivers from the table trip who are traveling by transport vehicle with
code 101 or 103

(5) To display the no and name of those drivers from the table trip who travelled between 2015-02-
10" and 2015-04-01'

(6) To display all the details from table trip in which the distance is travelled is more than 100 KM in
ascending order of no

(7) Predict the output


select count(*),tcode from trip group by tcode having count(*)>1;

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(8) Predict the output


select distinct tcode from trip ;

(9) Predict the output


select a.tcode,name,ttype from trip a,transport b where a.tcode=b.tcode and km<90 ;

(10) Predict the output


select name, km*perkm from trip a, transport b where a.tcode=b.tcode and a.tcode=105 ;

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

DOUBLE TABLE 6

(1) Create the above two tables

(2) Insert records into it

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(3) To display those company name which are having prize less than 30000.

(4) To display the name of the companies in reverse alphabetical order.

(5) To increase the prize by 1000 for those customer whose name starts with S.

(6) To add one more column totalprice with decimal] 10,2) to the table customer

(7) Predict the output


select count(*) , city from company group by city;

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

(8) Predict the output


select avg(qty) from customer where name like "%r%”;

(9) Predict the output


select min(price), max(price) from customer where qty> 10;

(10) Predict the output


select productname, city, price from company, customer where company.
cid=customer.cid;

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

CONNECTIVITY
PROGRAMS

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

1. 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:
• Insert two records in it
• Display the contents of the table

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:
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE

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

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

2. Create a table Electronics in mysql using connectivity with python idle. Also insert records
into the table.

import mysql.connector as cspractical


csp=cspractical.connect(host="localhost",user="root",passwd="aastha",database="xiics")
cspr=csp.cursor()
cspr.execute("create table electronics(ModelNo char(4) primary key,ProductName
varchar(100),Price integer,DateOfSell date,Company varchar(20))")
def insert():
x=int(input("How Many records do you want to enter:"))
for i in range(x):
y=input("enter 4 digit model no.:")
z=input("enter the product name:")
g=int(input("enter the price:"))
f=input("enter date (yyyy-mm-dd):")
h=input("enter the company name:")
cspr.execute("insert into electronics values(%s,%s,%s,%s,%s)",(y,z,g,f,h))
csp.commit()
def display():
cspr.execute("select * from electronics")
for i in cspr:
print(i)

while True:
print("1:INSERT")
print("2:DISPLAY")
print("0:EXIT")
ch=int(input("enter your choice:"))
if ch==1:
insert()
elif ch==2:
display()
else:
break

VISHESH AGGARWAL XII-A 2021-2022


COMPUTER SCIENCE PRACTICAL FILE

OUTPUT

VISHESH AGGARWAL XII-A 2021-2022

You might also like