MySQL Practical File
MySQL Practical File
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).
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.
STACKS
PROGRAMS
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]
OUTP
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
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")
if ch==1:nm
push()
print("Element Pushed")
elif ch==2:
pop_ele()
elif ch==3:
display()
else:
print("Invalid Choice")
OUTPUT
(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
SINGLE TABLE
QUESTIONS
TABLE 1
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE
Sol.
(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’.
(6) WAQ to display name, hiring date of those employees who are hired in 1990.
TABLE 2
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE
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.
(4) Ram’s budget is Rs.54 and Cruise is his favourite actor. WAQ to display the movies he can watch
(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
TABLE 4
(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.
(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
TABLE 5
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE
(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.
(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;
TABLE 6
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE
(3) Shreya has interest in learning programming languages . WAQ to suggest her some books.
(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.
TABLE 7
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE
(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.
TABLE 8
VISHESH AGGARWAL XII-A 2021-2022
COMPUTER SCIENCE PRACTICAL FILE
(3) Display the names of the students who have grade 'C' in either Game1 or Game2 or both.
(4) Display the games taken up by the students, whose name starts with 'A'.
TABLE 9
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.
Table 10
(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.
DOUBLE TABLE
QUESTIONS
DOUBLE TABLE 1
(1) Create the above two tables and linkage between them.
(3) WAQ to display the name of books and their quantity issued.
(4) WAQ to display the no. of books left after getting issued.
DOUBLE TABLE 2
(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
DOUBLE TABLE 3
(3) WAQ to display the names of player and the games they will play.
(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
DOUBLE TABLE 4
(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.
DOUBLE TABLE 5
(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
DOUBLE TABLE 6
(3) To display those company name which are having prize less than 30000.
(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
CONNECTIVITY
PROGRAMS
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
2. Create a table Electronics in mysql using connectivity with python idle. Also insert records
into the table.
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
OUTPUT