0% found this document useful (1 vote)
740 views4 pages

Practical Questions Mysql For Record 2023-24

Nothing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
740 views4 pages

Practical Questions Mysql For Record 2023-24

Nothing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PRACTICAL QUESTIONS MYSQL FOR RECORD 2023-24

Q1.

Write SQL queries for the following:


a. Display the details of all the loans with less than 40 instalments in ascending order of
name and whose name ends with a.
b. Display the details of all the loans whose Loan_Amount is in the range 400000 to
500000. (Using BETWEEN operator) and whose interest rate is not null.
c. Make the AccNo of the table as primary key.
d. Increase the installments to 50 whose loan amount is 500000
e. Delete those records whose interest rate is less than 12.00%

Q2: In a database create the following tables with suitable constraints


i. Based on these tables write SQL statements for the following queries:
a) Display the lowest and the highest classes from the table STUDENTS.
b) Display the number of students in each class from the table STUDENTS.
c) Display the number of students in class 10.
d) Display details of the students of Cricket team.
e) Display the Admission number, name, class, section, and roll number of the students
whose grade in Sports table is 'A'
ii. Based on the above tables Predict the output of each of the following SQL statements,
a. SELECT class, sec, count(*) FROM students GROUP BY class, sec;
b. SELECT Game, COUNT(*) FROM Sports GROUP BY Game;
c. SELECT game, name, address FROM students, Sports WHERE students.admno =
sports.admno AND grade = 'A';
d. SELECT Game FROM students, Sports WHERE students.admno = sports.admno AND
Students.AdmNo = 1434;
e. SELECT coachname, count(*) from students,sports WHERE
students.admno=sports.admno group by coachname;

Q3: Program to connect with database and insert record of employee and display
records.
Solution:
import mysql.connector as mycon
con = mycon.connect(host='localhost',user='root',password="kv2uppal")
cur = con.cursor()
cur.execute("create database if not exists company")
cur.execute("use company")
cur.execute("create table if not exists employee(empno int, name varchar(20), dept
varchar(20),salary int)")
con.commit()
choice=None
while choice!=0:
print("1. ADD RECORD ")
print("2. DISPLAY RECORD ")
print("0. EXIT")
choice = int(input("Enter Choice :"))
if choice == 1:
e = int(input("Enter Employee Number :"))
n = input("Enter Name :")
d = input("Enter Department :")
s = int(input("Enter Salary :"))
query="insert into employee values({},'{}','{}',{})".format(e,n,d,s)
cur.execute(query)
con.commit()
print(" Data Saved Successfully")
elif choice == 2:
query="select * from employee" cur.execute(query)
result = cur.fetchall()
print("%10s"%"EMPNO","%20s"%"NAME","%15s"%"DEPARTMENT",
"%10s"%"SALARY")
for row in result:

print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3])
elif choice==0:
con.close()
print("Bye!!.....Thankyou ")
else:
print(" INVALID CHOICE ")
Q4: Program to connect with database and search employee number in table employee
and display record, if empno not found display appropriate message.
Solution:
import mysql.connector as mycon
con = mycon.connect(host='localhost',user='root',password="kv2uppal",
database="company")
cur = con.cursor()
print("EMPLOYEE SEARCHING FORM")
print("\n\n")
ans='y'
while ans.lower()=='y':
eno = int(input("ENTER EMPNO TO SEARCH :"))
query="select * from employee where empno={}".format(eno)
cur.execute(query)
result = cur.fetchall()
if cur.rowcount==0:
print("Sorry! Empno not found ")
else:
print("%10s"%"EMPNO","%20s"%"NAME","%15s"%"DEPARTMENT",
"%10s"%"SALARY")
for row in result:

print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3])
ans=input("SEARCH MORE (Y) :")

Q5: Program to connect with database and update the employee record of entered
empno.
Solution:
import mysql.connector as mycon
con = mycon.connect(host='localhost',user='root',password="kv2uppal",
database="company")
cur = con.cursor() print("#"*40)
print("EMPLOYEE UPDATION FORM")
print("#"*40)
print("\n\n")
ans='y'
while ans.lower()=='y':
eno = int(input("ENTER EMPNO TO UPDATE :"))
query="select * from employee where empno={}".format(eno)
cur.execute(query)
result = cur.fetchall()
if cur.rowcount==0:
print("Sorry! Empno not found ")
else:

print("%10s"%"EMPNO","%20s"%"NAME","%15s"%"DEPARTMENT",
"%10s"%"SALARY")
for row in result:

print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3])
choice=input("\n ARE YOUR SURE TO UPDATE ? (Y) :")
if choice.lower()=='y':
print(" YOU CAN UPDATE ONLY DEPT AND SALARY")
d = input("ENTER NEW DEPARTMENT "))
s = int(input("ENTER NEW SALARY,( "))
query="update employee set dept='{}',salary={} where
empno={}".format(d,s,eno)
cur.execute(query)
con.commit()
print(" RECORD UPDATED ")
ans=input("UPDATE MORE (Y) :")
Q6: Program to connect with database and delete the record of entered employee
number.

Solution:
import mysql.connector as mycon
con = mycon.connect(host='localhost',user='root',password="kv2uppal",
database="company")
cur = con.cursor()
print("EMPLOYEE DELETION FORM")
print("\n\n")
ans='y'
while ans.lower()=='y':
eno = int(input("ENTER EMPNO TO DELETE :"))
query="select * from employee where empno={}".format(eno)
cur.execute(query)
result = cur.fetchall()
if cur.rowcount==0:
print("Sorry! Empno not found ")
else:
print("%10s"%"EMPNO","%20s"%"NAME",
"%15s"%"DEPARTMENT", "%10s"%"SALARY")
for row in result:
print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3])
choice=input("\n ARE YOUR SURE TO DELETE ? (Y) :")
if choice.lower()=='y':
query="delete from employee where empno={}".format(eno)
cur.execute(query)
con.commit()
print(" RECORD DELETED SUCCESSFULLY! ")
ans=input("DELETE MORE ? (Y) :")

You might also like