0% found this document useful (0 votes)
7 views83 pages

Abhi Abhi

The document is a practical file for Class 12 Computer Science for the session 2024-25, detailing various Python and MySQL programming tasks. It includes a table of contents listing practical exercises such as calculating factorials, file handling, and database operations. Each practical is accompanied by sample code and expected outputs.

Uploaded by

www.suraj3000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views83 pages

Abhi Abhi

The document is a practical file for Class 12 Computer Science for the session 2024-25, detailing various Python and MySQL programming tasks. It includes a table of contents listing practical exercises such as calculating factorials, file handling, and database operations. Each practical is accompanied by sample code and expected outputs.

Uploaded by

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

CS PRACTICLE FILE SESSION 2024-25 CLASS 12

COMPUTER SCIENCE
PRACTICLE FILE

GSBV BURARI
(2024-2025)

SUBMITTED BY :- Roshan SUBMITTED TO :- SP SHARMA SIR


ROLL NO :- 22 LECTURER CS/IP
CLASS :- 12th
SECTION :- A

0 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Table Of Content
S.No. Practical Name Page No. Teacher’s
Sign
PYTHON PRACTICALS
1. WAP in Python to find the factorial of a number using
function.
2. WAP in Python to implement default and positional
parameters.
3. Write a program in Python to input the value of x and n and
print the sum of the following series
1+x+x^2+x^3+ ---------------- x^n
4. WAP in Python to read a text file and print the number of
vowels and consonants in the file.
5. WAP in Python to read a text file and print the line or
paragraph starting with the letter ‘S’
6. WAP in Python to read a text file and print the number of
uppercase and lowercase letters in the file.
7. WAP in Python to create a binary file with name and roll
number of the students. Search for a given roll number and
display the name of student.
8. Create a binary file with roll_no, name and marks of some
students and update the marks of specific student.
9. Create a binary file with eid, ename and salary and update
the salary of the employee.
10. Create a text file and remove the lines from the file which
contains letter ‘K’
11. Create a binary file with 10 random numbers from 1 to 40
and print those numbers.
12. Write a program in Python to create a CSV file with the
details of 5 students.
13. WAP in Python to read a CSV file.

14. Write a menu driven program which insert, delete and


display the details of an employee such as eid, ename and
salary using Stack.
15. Write a menu driven program which insert, delete and display
the details of a book such as book_id, book_name and price
using Stack.
16. Write a menu driven program which insert, delete and
display the details of a student such as roll_no, sname and

1 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

course using Stack.


17. Write a menu driven program which insert, delete and
display the details of a movie such as movie_id, mname and
rating using Stack.
18. Write a menu driven program which insert, delete and
display the details of a product such as pid, pname and price
using Stack.
19. Write a menu driven program which insert, delete and
display the details of a club such as club_id, cname and city
using Stack.
20. Write a menu driven program to demonstrate add, display,
update, delete and exit. Performed on a table Book containing
(bid, bname, bprice) through python-MySql
connectivity.
21. Write a menu driven program to demonstrate add, display,
update, delete and exit. Performed on a table Product
containing (pid, pname, price) through python-MySql
connectivity.
22. Write a menu driven program to demonstrate add, display,
update, delete and exit. Performed on a table club containing
(club_id, cname, city) through python-MySql connectivity.
23. Write a menu driven program to demonstrate add, display,
update, delete and exit. Performed on a table student
containing (sid, sname, course) through python-MySql
connectivity.
24. Write a menu driven program to demonstrate add, display,
update, delete and exit. Performed on a table movie
containing (mid, mname, rating) through python-MySql
connectivity.
25. Write a menu driven program to demonstrate add, display,
update, delete and exit. Performed on a table Employee
containing (eid, ename, salary) through python-MySql
connectivity.

MYSQL PRACTICALS
1. Write a SQL query to create a database.

2. Write a SQL query to create a student table with the student


id, class, section, gender, name, dob, and marks as attributes
where the student id is the primary key.
3. Write a SQL query to insert the details of at least 10 students
in the student table.

2 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

4. Write a SQL query to delete the details of a particular student


in the student table.
5. Write a SQL query to increase the marks by 5% for those
students who are scoring marks more than 30.
6. Write a SQL query to display the entire content of the table.

7. Write a SQL query to display student_id, name and marks of


those students who are scoring marks more than 30.
8. Write a SQL query to find the average marks from the
student table.
9. Write a SQL query to find the number of students, who are
from section ‘A’.
10. Write a SQL query to add a new column email in the student
table with appropriate data type.
11. Write a SQL query to add the email id’s of each student in the
previously created email column.
12. Write a SQL query to display the information of all the
students, whose name starts with ‘S’
13. Write a SQL query to display the student_id, name, dob of
those students who are born between ‘2005-01-01’ and ‘2005-
12-31’
14. Write a SQL query to display the student_id, name, dob,marks,
email of male students in ascending order of their
name
15. Write a SQL query to display the student_id, gender, name,
dob, marks, email of students in descending order of their
marks.
16. Write a SQL query to display the unique section name from
the student table.
17. Create a student table with student id, name and marks as
attribute, where the student id is the primary key.
18. Insert the details of 5 students in the student table.

19. Delete the details of a student in the student table.

20. Use the Select command to get the details of the students
with marks more than 30.
21. Shiva, a student of class XII, created a table “CLASS”. Grade is
one of the columns of this table. Write the SQL query to find
the details of students whose grade have not been entered.
22. Shiva is using a table with the following details:
Students(Name, Class, Stream_id, Stream_Name)
Write the SQL query to display the names of students who

3 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

have not been assigned any stream or have been assigned


Stream_Name that end with “computers”
23. Write the difference between drop, delete and truncate
command with example.
24. Write the sort notes on group by, having and where clause
with example.
25. Write the SQL query to find out the square root of 26.

26. Shiva is using a table employee. It has following details:


Employee (Code, Name, Salary, DeptCode). Write the SQL
query to display maximum salary department wise.
27. Write the SQL Query to display the difference of highest and
lowest salary of each department having maximum salary
greater than 4000.
28. Write the SQL Query to increase 20% salary ofthe employee
whose experience is more than 5 year of the table Emp(id,
name, salary, exp)
29. Write the SQL Query for inner join of two tables Emp(eid,
ename, salary, dept_id) and Dept(dept_id, dname)
30. Write the SQL Query for full outer join of two tables Emp(eid,
ename,salary,dept_id) and Dept(dept_id, dname)
31. Write a SQL to Enter 5 Employee data in a single query in the
table Emp (eid, ename, salary, city, dob).
32. Display 4 characters extracted from 5th right character
onwards from string ‘ABCDEFG’.
33. Write a query to create a string from the ASCII values 65,
67.3, ‘68.3’
34. Display names ‘MR. MODI’ and ‘MR. ’ into lowercase.

35. How many characters are there in string ‘CANDIDE’.

36. Create a customer (customer_id, name, country) table and


find the number of customer from each country in the table
using group by.
37. Consider the following SQL String “Active Number” and write
the command to display:
a. “Act” b. “Numb”
38. Write any one similarity and one difference between Primary
key and unique key constraint
39. Write the difference between char() and varchar()

40. Write the difference between count(column_name) and


count(*)

4 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Practical No - 1: WAP in Python to find the factorial of a number using


function.
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
number = int(input("Enter a number: "))
if number < 0:
print("Factorial is not defined for negative numbers.")
else:
result = factorial(number)
print(f"The factorial of {number} is {result}")

OUTPUT:
Enter a number: 4
The factorial of 4 is 24

Enter a number: 6
The factorial of 6 is 720

Enter a number: 10
The factorial of 10 is 3628800

Enter a number: 3
The factorial of 3 is 6

Enter a number: 1
The factorial of 1 is 1

Enter a number: 9
The factorial of 9 is 362880

5 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Practical No – 2: WAP in Python to implement default and


positional parameters.

#Default Parameter

def show(a,b,c=8):
print("Sum=",(a+b+c))

show(5,6)
show(5,6,10)

def show1(a,b=9,c=8):
print("Sum1=",(a+b+c))

show1(5) show1(5,6)
show1(5,6,10)

#Positional Parameter def

show2(a,b):
print("Sub=",(a-b))

show2(15,6)
show2(6,15)

OUTPUT:

Sum= 19
Sum= 21
Sum1= 22
Sum1= 19
Sum1= 21
Sub= 9
Sub= -9

6 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Practical No - 3: Write a program in Python to input the value of x and n


and print the sum of the following series.

x=int(input("Enter the value of x: "))


n=int(input("Enter the value of n: ")) sum=0
for i in range(0,n+1):
sum=sum+x**i

print("Sum of series=",sum)

OUTPUT:

Enter the value of x: 4

Enter the value of n: 3

Sum of series= 85

Practical No - 4: WAP in Python to read a text file and print the


number of vowels and consonants in the file.

f=open("Vowel.txt","r")
data=f.read()
V=['A','E','I','O','U','a','e','i','o','u']
C=['B','C','D','F','G','H','J','K','L','M','N','P','Q','R','S','T','V','W','X', \
'Y','Z','b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w', \
'x','y','z']

cv=0
cc=0
for i in data:
if i in V:
cv=cv+1
elif i in C:
cc=cc+1

ct=0
for i in data:
ct=ct+1
print("Number of Vowels in the file=",cv)
print("Number of Consonants in the file=",cc)
print("Number of Total Chars in the file=",ct)
f.close()

7 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

OUTPUT:

Number of Vowels in the file= 184


Number of Consonants in the file= 335

Number of Total Chars in the file= 650

Practical No - 5: WAP in Python to read a text file and print the


line or paragraph starting with the letter ‘S’
f=open("abc.txt","r")
line=f.readline()

lc=0

while line:

if line[0]=='s' or line[0]=='S':

print(line,end="")

lc=lc+1

line=f.readline()

f.close()

print("Total number of lines start with 's' or 'S'=",lc)

OUTPUT:
Sam

SameerSanjay

Sunil

Total number of lines start with 's' or 'S'= 4

8 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Practical No - 6: WAP in Python to read a text file and print the


number of uppercase and lowercase letters in the file.

f=open("Vowel.txt","r")
data=f.read()
U=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R', \
'S','T','U','V','W','X','Y','Z',]
L=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r', \
's','t','u','v','w','x','y','z']
cu=0
cl=0
for i in data:
if i in U:
cu=cu+1
elif i in L:
cl=cl+1
ct=0
for i in data:
ct=ct+1
print("Number of Uppercase letters in the file=",cu)
print("Number of Lowercase Letters in the file=",cl)
print("Number of Total Chars in the file=",ct)
f.close()

OUTPUT:

Number of Uppercase letters in the file= 139

Number of Lowercase Letters in the file= 380

Number of Total Chars in the file= 650

9 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Practical No - 7: WAP in Python to create a binary file with


name and roll number of the students. Search for a given roll
number and display the name of student.
import pickle

S={}

f=open('stud.dat','wb')

c='y'

while c=='y' or c=='Y':

rno=int(input("Enter the roll no. of the student : "))

name=input("Enter the name of the student: ")

S['RollNo']=rno

S['Name']=name

pickle.dump(S,f)

c=input("Do You Want to add more students(y/n): ")

f.close()

f=open('stud.dat','rb')

rno=int(input("Enter the roll no. of the student to be search: "))

K={}

m=0

try:

while True:

K=pickle.load(f)

if K["RollNo"] == rno:

print(K)

m=m+1

except EOFError:

f.close()

if m==0:

print("Student not Found")

10 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

OUTPUT:
Enter the roll no. of the student : 1

Enter the name of the student: Ram

Do You Want to add more students(y/n): y

Enter the roll no. of the student : 2

Enter the name of the student: Raj

Do You Want to add more students(y/n): y

Enter the roll no. of the student : 3

Enter the name of the student: Sam

Do You Want to add more students(y/n): n

Enter the roll no. of the student to be search: 2

{'RollNo': 2, 'Name': 'Raj'}

Practical No - 8: Create a binary file with roll_no, name and


marks of some students and update the marks of specific
student.

import pickle
S={}
f=open('stud.dat','wb')
c='y'
while c=='y' or c=='Y':
rno=int(input("Enter the roll no. of the student : "))

name=input("Enter the name of the student: ")

marks=int(input("Enter the marks of the student: "))

S['RollNo']=rno

S['Name']=name

11 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

S['Marks']=marks

pickle.dump(S,f)

c=input("Do You Want to add more students(y/n): ")

f.close()

f=open('stud.dat','rb+')

rno=int(input("Enter the roll no. of the student to be updated: "))

marks=int(input("Enter the updated marks of the student: "))

f.seek(0,0)
m=0

try:

while True:

pos=f.tell()

S=pickle.load(f)

if S["RollNo"] == rno:

f.seek(pos)

S["Marks"]=marks

pickle.dump(S,f)

m=m+1

12 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

except EOFError:

f.close()

if m==0:

print("Student not Found")

else:

f=open('stud.dat','rb')

try:

while True:

S=pickle.load(f)

print(S)

except EOFError:

f.close()

OUTPUT:

Enter the roll no. of the student : 1

Enter the name of the student: Ram

Enter the marks of the student: 25

Do You Want to add more students(y/n): y

Enter the roll no. of the student : 2

13 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Enter the name of the student: Raj

Enter the marks of the student: 35

Do You Want to add more students(y/n): y

Enter the roll no. of the student : 3

Enter the name of the student: Sam

Enter the marks of the student: 32

Do You Want to add more students(y/n): n

Enter the roll no. of the student to be updated: 2

Enter the updated marks of the student: 40

{'RollNo': 1, 'Name': 'Ram', 'Marks': 25}

{'RollNo': 2, 'Name': 'Raj', 'Marks': 40}

{'RollNo': 3, 'Name': 'Sam', 'Marks': 32}

Practical No - 9: Create a binary file with eid, ename and


salary and update the salary of the employee.
import pickle

E={}

f=open('emp.dat','wb')

c='y'

while c=='y' or c=='Y':

eid=int(input("Enter the Emp Id of the Employee : "))

ename=input("Enter the name of the Employee: ")

14 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

salary=float(input("Enter the salary of the Employee: "))

E['Emp_Id']=eid

E['Emp_Name']=ename

E['Salary']=salary

pickle.dump(E,f)

c=input("Do You Want to add more employee(y/n): ")

f.close()

f=open('emp.dat','rb+')

eid=int(input("Enter the Emp Id of the employee to be updated: "))

salary=float(input("Enter the updated salary of the employee: "))

f.seek(0,0)

m=0

try:

while True:

pos=f.tell()

E=pickle.load(f)

if E["Emp_Id"] == eid:

f.seek(pos)

E["Salary"]=salary

pickle.dump(E,f)

m=m+1

except EOFError:

f.close()

if m==0:

print("Employee not Found")

else:

f=open('emp.dat','rb')

try:

while True:

E=pickle.load(f)

print(E)

except EOFError:
15 Suraj Kumar GSBV(BURARI)
CS PRACTICLE FILE SESSION 2024-25 CLASS 12

OUTPUT:

Enter the Emp Id of the Employee : 101

Enter the name of the Employee: Ram

Enter the salary of the Employee: 15000

Do You Want to add more employee(y/n): y

Enter the Emp Id of the Employee : 102

Enter the name of the Employee: Raj

Enter the salary of the Employee: 18000

Do You Want to add more employee(y/n): y

Enter the Emp Id of the Employee : 103

Enter the name of the Employee: Sam

Enter the salary of the Employee: 25000

Do You Want to add more employee(y/n): n

Enter the Emp Id of the employee to be updated: 102

Enter the updated salary of the employee: 22000

{'Emp_Id': 101, 'Emp_Name': 'Ram', 'Salary': 15000.0}

{'Emp_Id': 102, 'Emp_Name': 'Raj', 'Salary': 22000.0}

{'Emp_Id': 103, 'Emp_Name': 'Sam', 'Salary': 25000.0}

16 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Practical No - 10: Create a text file and remove the lines from
the file which contains letter ‘K’
import sys

f=open("sps.txt","w+")

print("Enter the lines/data to insert in the file: ")

data = sys.stdin.readlines()

for i in data:

f.write(i)

f.close()

print("**********")

print("Content of File: ")

f=open("sps.txt","r")

data=f.read()

print(data)

f.close()

f=open("sps.txt","r+")

data=f.readlines()

f.seek(0)

for i in data:

if "K" not in i:

f.write(i)

f.truncate()

f.close()

print("**********")

print("Content of File After Deletion: ")

f=open("sps.txt","r")

data=f.read()

print(data)

17 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

OUTPUT:

Enter the lines/data to insert in the file:

SUN

HELLO INDIA

KARAN

SAM

RAM

KASHMIR

DELHI

**********

Content of File:

SUN

HELLO INDIA

KARAN

SAM

RAM

KASHMIR

DELH

**********

Content of File After Deletion:

SUN

HELLO INDIA

SAM

RAM

DELHI

Practical No - 11: Create a binary file with 10 random numbers


from 1 to 40 and print those numbers.

18 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

import pickle,random

N=[]

f=open("sps.txt","wb")

for i in range(10):

N.append(random.randint(1,40))

pickle.dump(N,f)

f.close()

print("File Created:")

print("Content of File:")

f=open("sps.txt","rb")

data=pickle.load(f)

for i in data:

print(i)

f.close()

OUTPUT:

File Created:

Content of File:

24

14

18

14

26

33

10

33

19 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Practical No - 12: Write a program in Python to create a CSV


file with the details of 5 students.

import csv

f=open("student.csv","w",newline='')

cw=csv.writer(f)

cw.writerow(['Rollno','Name','Marks'])

for i in range(5):

print("Student Record of ",(i+1))

rollno=int(input("Enter Roll No. : "))

name=input("Enter Name: ")

marks=float(input("Enter Marks: "))

sr=[rollno,name,marks]

cw.writerow(sr)

f.close()

print("File Created Successfully")

OUTPUT:

Student Record of 1

Enter Roll No. : 11

Enter Name: Shiva

Enter Marks: 34

Student Record of 2

Enter Roll No. : 23

Enter Name: Saanvi

Enter Marks: 37

Student Record of 3

Enter Roll No. : 27

Enter Name: Sachin

Enter Marks: 24

20 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Student Record of 4

Enter Roll No. : 28

Enter Name: Ram : 20

Enter Marks: 40

Student Record of 5

Enter Roll No. : 29

Enter Name: Raj

Enter Marks: 37

File Created Successfully

Practical No - 13: WAP in Python to read a CSV file.

import csv

f=open("student.csv","r")

cr=csv.reader(f)

print("Content of CSV File: ")

for r in cr:

print(r)

f.close()

OUTPUT:

Content of CSV File:

['Rollno', 'Name', 'Marks']

['11', 'Shiva', '34.0']

['23', 'Saanvi', '37.0']

['27', 'Sachin', '24.0']

['28', 'Ram', '40.0']

['29', 'Raj', '37.0']

21 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Practical No - 14: Write a menu driven program which insert,


delete and display the details of an employee such as eid,
ename and salary using Stack.

Employee=[]

c='y'

while(c=="y" or c=="Y"):

print("1: Add Employee Detail: ")

print("2: Delete Employee Detail: ")

print("3: Display Employee Detail: ")

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

if(choice==1):

eid=int(input("Enter Employee Id: "))

ename=input("Enter Employee Name: ")

salary=float(input("Enter Employee Salary: "))

emp=(eid,ename,salary)

Employee.append(emp)

elif(choice==2):

if(Employee==[]):

print("Stack Empty")

else:

print("Deleted element is: ",Employee.pop())

elif(choice==3):

L=len(Employee)

while(L>0):

print(Employee[L-1])

L=L-1

else:

print("Wrong Input")

c=input("Do you want to continue? Press 'y' to Continue: ")

22 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

OUTPUT:

1: Add Employee Detail:

2: Delete Employee Detail:

3: Display Employee Detail:

Enter your choice: 1

Enter Employee Id: 101

Enter Employee Name: Shiva

Enter Employee Salary: 25000

Do you want to continue? Press 'y' to Continue: y

1: Add Employee Detail:

2: Delete Employee Detail:

3: Display Employee Detail:

Enter your choice: 1

Enter Employee Id: 102

Enter Employee Name: Saanvi

Enter Employee Salary: 22000

Do you want to continue? Press 'y' to Continue: y

1: Add Employee Detail:

2: Delete Employee Detail:

3: Display Employee Detail:

Enter your choice: 1

Enter Employee Id: 103

Enter Employee Name: Sachin

Enter Employee Salary: 30000

Do you want to continue? Press 'y' to Continue: y

1: Add Employee Detail:

2: Delete Employee Detail:

3: Display Employee Detail:

Enter your choice: 3

(103, 'Sachin', 30000.0)

(102, 'Saanvi', 22000.0)

23 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

(101, 'Shiva', 25000.0)

Do you want to continue? Press 'y' to Continue: y

1: Add Employee Detail:

2: Delete Employee Detail:

3: Display Employee Detail:

Enter your choice: 2

Deleted element is: (103, 'Sachin', 30000.0)

Do you want to continue? Press 'y' to Continue: y

1: Add Employee Detail:

2: Delete Employee Detail:

3: Display Employee Detail:

Enter your choice: 3

(102, 'Saanvi', 22000.0)

(101, 'Shiva', 25000.0)

Do you want to continue? Press 'y' to Continue: n

Practical No - 15: Write a menu driven program which insert,


delete and display the details of a book such as book_id,
book_name and price using Stack.

Book=[]

c='y'

while(c=='y' or c=='Y'):

print("1: Add Book Details: ")

print("2: Delete Book Details: ")

print("3: Display Book Details: ")

choice=int(input("Enter Your Choice: "))

if(choice==1):

book_id=int(input("Enter Book Id: "))

book_name=input("Enter Book Name: ")

price=float(input("Enter Book Price: "))

B=(book_id,book_name,price)

24 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Book.append(B)

elif(choice==2):

if(Book==[]):

print("Stack Empty")

else:

print("Deleted element is: ",Book.pop())

elif(choice==3):

L=len(Book)

while(L>0):

print(Book [L-1])

L=L-1

else:

print("Wrong Input")

c=input("Do you want to continue? press 'y' to continue: ")

OUTPUT:

1: Add Book Details:

2: Delete Book Details:

3: Display Book Details:

Enter Your Choice: 1

Enter Book Id: 101

Enter Book Name: CS CRACKER

Enter Book Price: 350

Do you want to continue? press 'y' to continue: Y

1: Add Book Details:

2: Delete Book Details:

3: Display Book Details:

Enter Your Choice: 1

Enter Book Id: 102

Enter Book Name: PYTHON

Enter Book Price: 400

25 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Do you want to continue? press 'y' to continue: Y

1: Add Book Details:

2: Delete Book Details:

3: Display Book Details:

Enter Your Choice: 1

Enter Book Id: 103

Enter Book Name: SQL

Enter Book Price: 300

Do you want to continue? press 'y' to continue: Y

1: Add Book Details:

2: Delete Book Details:

3: Display Book Details:

Enter Your Choice: 3

(103, 'SQL', 300.0)

(102, 'PYTHON', 400.0)

(101, 'CS CRACKER', 350.0)

Do you want to continue? press 'y' to continue: Y

1: Add Book Details:

2: Delete Book Details:

3: Display Book Details:

Enter Your Choice: 2

Deleted element is: (103, 'SQL', 300.0)

Do you want to continue? press 'y' to continue: Y

1: Add Book Details:

2: Delete Book Details:

3: Display Book Details:

Enter Your Choice: 3

(102, 'PYTHON', 400.0)

(101, 'CS CRACKER', 350.0)

Do you want to continue? press 'y' to continue: N

26 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Practical No - 16: Write a menu driven program which insert,


delete and display the details of a student such as roll_no,
name and course using Stack.

Student=[]

c='y'

while(c=='y' or c=='Y'):

print("1 : Add Student Details : ")

print("2 : Delete Student Details : ")

print("3 : Display Student Details : ")

choice=int(input("Enter Your Choice: "))

if(choice==1):

roll_no=int(input("Enter Student Roll no: "))

sname=input("Enter Student Name: ")

course=input("Enter Student Course: ")

stu=(roll_no, sname, course)

Student.append(stu)

elif(choice==2):

if(Student==[]):

print("Stack Empty")

else:

print("Deleted Element is : ", Student.pop())

elif(choice==3):

L=len(Student)

while(L>0):

print(Student[L-1])

L=L-1

else:

print("wrong input")

c=input("Do you want to continue ? press 'y' to continue; ")

27 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

OUTPUT:

1 : Add Student Details :

2 : Delete Student Details :

3 : Display Student Details :

Enter Your Choice: 1

Enter Student Roll no: 1

Enter Student Name: Shiva

Enter Student Course: BCA

Do you want to continue ? press 'y' to continue; y

1 : Add Student Details :

2 : Delete Student Details :

3 : Display Student Details :

Enter Your Choice: 1

Enter Student Roll no: 2

Enter Student Name: Saanvi

Enter Student Course: B.Tech.

Do you want to continue ? press 'y' to continue; y

1 : Add Student Details :

2 : Delete Student Details :

3 : Display Student Details :

Enter Your Choice: 1

Enter Student Roll no: 3

Enter Student Name: Sachin

Enter Student Course: MCA

Do you want to continue ? press 'y' to continue; y

1 : Add Student Details :

2 : Delete Student Details :

3 : Display Student Details :

Enter Your Choice: 3

(3, 'Sachin', 'MCA')

(2, 'Saanvi', 'B.Tech.')

28 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

(1, 'Shiva', 'BCA')

Do you want to continue ? press 'y' to continue; y

1 : Add Student Details :

2 : Delete Student Details :

3 : Display Student Details :

Enter Your Choice: 2

Deleted Element is : (3, 'Sachin', 'MCA')

Do you want to continue ? press 'y' to continue; y

1 : Add Student Details :

2 : Delete Student Details :

3 : Display Student Details :

Enter Your Choice: 3

(2, 'Saanvi', 'B.Tech.')

(1, 'Shiva', 'BCA')

Do you want to continue ? press 'y' to continue; n

Practical No - 17: Write a menu driven program which insert,


delete and display the details of a movie such as movie_id,
mname and rating using Stack.

movie=[]

c='y'

while(c=='y' or c=='Y'):

print("1:Add Movie Details:")

print("2:Delete Movie Details:")

print("3:Display Movie Details:")

Choice=int(input("Enter Your Choice:"))

if(Choice==1):

mid=int(input("Enter Movie id: "))

mname=input("Enter Movie Name: ")

rating=float(input("Enter Movie Rating: "))

mov= (mid,mname,rating)

29 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

movie.append(mov)

elif(Choice==2):

if(movie==[]):

print("stack empty")

else:

print("Deleted element is: ",movie.pop())

elif(Choice==3):

L=len(movie)

while(L>0):

print(movie[L-1])

L=L-1

else:

print("wrong input")

c=input("Do you want to continue? press 'y' to continue: ")

OUTPUT:

1:Add Movie Details:

2:Delete Movie Details:

3:Display Movie Details:

Enter Your Choice:1

Enter Movie id: 101

Enter Movie Name: Gadar

Enter Movie Rating: 4.8

Do you want to continue? press 'y' to continue: y

1:Add Movie Details:

2:Delete Movie Details:

3:Display Movie Details:

Enter Your Choice:1

Enter Movie id: 102

Enter Movie Name: Indian

Enter Movie Rating: 5.0

30 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Do you want to continue? press 'y' to continue: y

1:Add Movie Details:

2:Delete Movie Details:

3:Display Movie Details:

Enter Your Choice:1

Enter Movie id: 103

Enter Movie Name: Ghatak

Enter Movie Rating: 4.9

Do you want to continue? press 'y' to continue: y

1:Add Movie Details:

2:Delete Movie Details:

3:Display Movie Details:

Enter Your Choice:3

(103, 'Ghatak', 4.9)

(102, 'Indian', 5.0)

(101, 'Gadar', 4.8)

Do you want to continue? press 'y' to continue: y

1:Add Movie Details:

2:Delete Movie Details:

3:Display Movie Details:

Enter Your Choice:2

Deleted element is: (103, 'Ghatak', 4.9)

Do you want to continue? press 'y' to continue: y

1:Add Movie Details:

2:Delete Movie Details:

3:Display Movie Details:

Enter Your Choice:3

(102, 'Indian', 5.0)

(101, 'Gadar', 4.8)

Do you want to continue? press 'y' to continue: n

31 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Practical No - 18: Write a menu driven program which insert,


delete and display the details of a product such as pid, pname
and price using Stack.

Product=[ ]

c="y"

while(c=="y" or c=="Y"):

print("1: Insert Product Details: ")

print("2: Delete Product Details: ")

print("3: Display Product Details: ")

choice=int(input("Enter Your Choice: "))

if(choice==1):

pid=int(input("Enter Product Id: "))

pname=input("Enter Product Name: ")

price=float(input("Enter Product Price: "))

Prd=(pid,pname,price)

Product.append(Prd)

elif(choice==2):

if(Product==[ ]):

print("Stack Empty")

else:

print("Deleted Product is: ",Product.pop())

elif(choice==3):

L=len(Product)

while(L>0):

print(Product[L-1])

L=L-1

else:

print("Wrong input")

c=input("Do you want to continue?, Press 'y' to continue: ")

32 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

OUTPUT:

1: Insert Product Details:

2: Delete Product Details:

3: Display Product Details:

Enter Your Choice: 1

Enter Product Id: 101

Enter Product Name: Book

Enter Product Price: 230

Do you want to continue?, Press 'y' to continue: y

1: Insert Product Details:

2: Delete Product Details:

3: Display Product Details:

Enter Your Choice: 1

Enter Product Id: 102

Enter Product Name: Pen

Enter Product Price: 30

Do you want to continue?, Press 'y' to continue: y

1: Insert Product Details:

2: Delete Product Details:

3: Display Product Details:

Enter Your Choice: 1

Enter Product Id: 103

Enter Product Name: Copy

Enter Product Price: 60

Do you want to continue?, Press 'y' to continue: y

1: Insert Product Details:

2: Delete Product Details:

3: Display Product Details:

Enter Your Choice: 3

(103, 'Copy', 60.0)

(102, 'Pen', 30.0)

33 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

(101, 'Book', 230.0)

Do you want to continue?, Press 'y' to continue: y

1: Insert Product Details:

2: Delete Product Details:

3: Display Product Details:

Enter Your Choice: 2

Deleted Product is: (103, 'Copy', 60.0)

Do you want to continue?, Press 'y' to continue: y

1: Insert Product Details:

2: Delete Product Details:

3: Display Product Details:

Enter Your Choice: 3

(102, 'Pen', 30.0)

(101, 'Book', 230.0)

Do you want to continue?, Press 'y' to continue: n

Practical No - 19: Write a menu driven program which insert,


delete and display the details of a club such as club_id, cname
and city using Stack.
Club= []
c='y'
while (c=="y" or c=="Y"):
print("1: Add Club Details: ")
print("2: Delete Club Details: ")
print("3: Display Club Details: ")
choice = int(input("Enter choice: "))
if (choice == 1):
cid = int(input("Enter Club Id: "))
cname = input("Enter Club Name: ")
city = input("Enter Club City: ")
clu = (cid,cname,city)
Club.append(clu)
elif (choice==2):

34 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

if(Club == []):
print(" Stack Empty ")
else:
print("Delete Element is : ", Club.pop())
elif (choice == 3):
L = len(Club)
while (L>0):
print(Club[L-1])
L=L-1
else:
print("Wrong Input")
c= input("Do you want to continue? Press 'y' to continue:")

OUTPUT:

1: Add Club Details:


2: Delete Club Details:
3: Display Club Details:
Enter choice: 1
Enter Club Id: 101
Enter Club Name: A1
Enter Club City: Delhi
Do you want to continue? Press 'y' to continue:y
1: Add Club Details:
2: Delete Club Details:
3: Display Club Details:
Enter choice: 1
Enter Club Id: 102
Enter Club Name: A2
Enter Club City: Noida
Do you want to continue? Press 'y' to continue:y
1: Add Club Details:
2: Delete Club Details:
3: Display Club Details:
35 Suraj Kumar GSBV(BURARI)
CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Enter choice: 1
Enter Club Id: 103
Enter Club Name: A3
Enter Club City: Delhi
Do you want to continue? Press 'y' to continue:y
1: Add Club Details:
2: Delete Club Details:
3: Display Club Details:
Enter choice: 3
(103, 'A3', 'Delhi')
(102, 'A2', 'Noida')
(101, 'A1', 'Delhi')
Do you want to continue? Press 'y' to continue:y
1: Add Club Details:
2: Delete Club Details:
3: Display Club Details:
Enter choice: 2
Delete Element is : (103, 'A3', 'Delhi')
Do you want to continue? Press 'y' to continue:y
1: Add Club Details:
2: Delete Club Details:
3: Display Club Details:
Enter choice: 3
(102, 'A2', 'Noida')
(101, 'A1', 'Delhi')
Do you want to continue? Press 'y' to continue:n

Practical No - 20: Write a menu driven program to demonstrate add,


display, update, delete and exit. Performed on a table Book containing
(bid, bname, bprice) through python-MySql connectivity.

36 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

import mysql.connector
con=mysql.connector.connect(host="localhost",username="root",passwd="root")
mycursor=con.cursor()
mycursor.execute("create database if not exists spg")
mycursor.execute("use spg")
mycursor.execute("create table if not exists book (bid int primary key,bname varchar(20),bprice
float(5,2))")
c="y"
while(c=="y" or c=="Y"):
print("1. Press 1 for add new book: ")
print("2. Press 2 for Show the details of Books: ")
print("3. Press 3 for Update Book Details: ")
print("4. Press 4 for Delete Book Details: ")
print("5. Press 5 for Exit: ")
choice=int(input("Enter Your Choice 1 or 2 or 3 or 4 or 5: "))
if(choice==1):
bid=int(input("Enter Book Id: "))
bname=input("Enter Book Name: ")
bprice=float(input("Enter Book Price: "))
mycursor.execute("insert into book values(%s,%s,%s)",(bid,bname,bprice))
con.commit()
elif(choice==2):
mycursor.execute("select * from book")
mybooks=mycursor.fetchall()
for x in mybooks:
print(x)
elif(choice==3):
bid=int(input("Enter the book id for update: "))
bname=input("Enter Book New Name: ")
bprice=float(input("Enter Book New Price: "))
mycursor.execute("update book set bname=%s,bprice=%s where
bid=%s",(bname,bprice,bid))
con.commit()

37 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

elif(choice==4):
bid=int(input("Enter the book id for delete: "))
mycursor.execute("delete from book where bid=%s",(bid,))
con.commit()
elif(choice==5):
break
else:
print("Wrong Choice")
c=input("Press 'y' for continue and 'n' for exit: ")

OUTPUT:

1. Press 1 for add new book:


2. Press 2 for Show the details of Books:
3. Press 3 for Update Book Details:
4. Press 4 for Delete Book Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 1
Enter Book Id: 101
Enter Book Name: CS CRACKER
Enter Book Price: 350
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new book:
2. Press 2 for Show the details of Books:
3. Press 3 for Update Book Details:
4. Press 4 for Delete Book Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 1
Enter Book Id: 102
Enter Book Name: CS with Python
Enter Book Price: 500
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new book:

38 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

2. Press 2 for Show the details of Books:


3. Press 3 for Update Book Details:
4. Press 4 for Delete Book Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(101, 'CS CRACKER', 350.0)
(102, 'CS with Python', 500.0)
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new book:
2. Press 2 for Show the details of Books:
3. Press 3 for Update Book Details:
4. Press 4 for Delete Book Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 3
Enter the book id for update: 102
Enter Book New Name: IP with Python
Enter Book New Price: 450
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new book:
2. Press 2 for Show the details of Books:
3. Press 3 for Update Book Details:
4. Press 4 for Delete Book Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(101, 'CS CRACKER', 350.0)
(102, 'IP with Python', 450.0)
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new book:
2. Press 2 for Show the details of Books:
3. Press 3 for Update Book Details:
4. Press 4 for Delete Book Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 4

39 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Enter the book id for delete: 102


Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new book:
2. Press 2 for Show the details of Books:
3. Press 3 for Update Book Details:
4. Press 4 for Delete Book Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(101, 'CS CRACKER', 350.0)
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new book:
2. Press 2 for Show the details of Books:
3. Press 3 for Update Book Details:
4. Press 4 for Delete Book Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 5

Practical No - 21: Write a menu driven program to demonstrate add,


display, update, delete and exit. Performed on a table Product containing
(pid, pname, price) through python-MySql connectivity.
import mysql.connector
con=mysql.connector.connect(host="localhost",username="root",passwd="root")
mycursor=con.cursor()
mycursor.execute("create database if not exists spg")
mycursor.execute("use spg")

mycursor.execute("create table if not exists product (pid int primary key,pname


varchar(20),pprice float(8,2))")

c="y"
while(c=="y" or c=="Y"):
print("1. Press 1 for add new product: ")

40 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

print("2. Press 2 for Show the details of product: ")


print("3. Press 3 for Update product Details: ")
print("4. Press 4 for Delete product Details: ")
print("5. Press 5 for Exit: ")
choice=int(input("Enter Your Choice 1 or 2 or 3 or 4 or 5: "))
if(choice==1):
pid=int(input("Enter product Id: "))
pname=input("Enter product Name: ")
pprice=float(input("Enter product Price: "))
mycursor.execute("insert into product values(%s,%s,%s)",(pid,pname,pprice))
con.commit()
elif(choice==2):
mycursor.execute("select * from product")
myproducts=mycursor.fetchall()
for x in myproducts:
print(x)
elif(choice==3):
pid=int(input("Enter the product id for update: "))
pname=input("Enter product New Name: ")
pprice=float(input("Enter product New Price: "))

mycursor.execute("update product set pname=%s,pprice=%s where


pid=%s",(pname,pprice,pid))

con.commit()
elif(choice==4):
pid=int(input("Enter the product id for delete: "))
mycursor.execute("delete from product where pid=%s",(pid,))
con.commit()
elif(choice==5):
break
else:
print("Wrong Choice")
c=input("Press 'y' for continue and 'n' for exit: ")
41 Suraj Kumar GSBV(BURARI)
CS PRACTICLE FILE SESSION 2024-25 CLASS 12

OUTPUT:

1. Press 1 for add new product:


2. Press 2 for Show the details of product:
3. Press 3 for Update product Details:
4. Press 4 for Delete product Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 1
Enter product Id: 101
Enter product Name: Keyboard
Enter product Price: 800
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new product:
2. Press 2 for Show the details of product:
3. Press 3 for Update product Details:
4. Press 4 for Delete product Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 1
Enter product Id: 102
Enter product Name: Mouse
Enter product Price: 600
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new product:
2. Press 2 for Show the details of product:
3. Press 3 for Update product Details:
4. Press 4 for Delete product Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(101, 'Keyboard', 800.0)
(102, 'Mouse', 600.0)
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new product:
2. Press 2 for Show the details of product:

42 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

3. Press 3 for Update product Details:


4. Press 4 for Delete product Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 3
Enter the product id for update: 102
Enter product New Name: Mouse
Enter product New Price: 900
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new product:
2. Press 2 for Show the details of product:
3. Press 3 for Update product Details:
4. Press 4 for Delete product Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(101, 'Keyboard', 800.0)
(102, 'Mouse', 900.0)
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new product:
2. Press 2 for Show the details of product:
3. Press 3 for Update product Details:
4. Press 4 for Delete product Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 4
Enter the product id for delete: 102
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new product:
2. Press 2 for Show the details of product:
3. Press 3 for Update product Details:
4. Press 4 for Delete product Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(101, 'Keyboard', 800.0)
Press 'y' for continue and 'n' for exit: y

43 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

1. Press 1 for add new product:


2. Press 2 for Show the details of product:
3. Press 3 for Update product Details:
4. Press 4 for Delete product Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 5

Practical No - 22: Write a menu driven program to demonstrate add,


display, update, delete and exit. Performed on a table club containing
(club_id, cname, city) through python-MySql connectivity.

import mysql.connector
con=mysql.connector.connect(host="localhost",username="root",passwd="root")
mycursor=con.cursor()
mycursor.execute("create database if not exists spg")
mycursor.execute("use spg")
mycursor.execute("create table if not exists club (cid int primary key, cname
varchar(20),city varchar(20))")
c="y"
while(c=="y" or c=="Y"):
print("1. Press 1 for add new club: ")
print("2. Press 2 for Show the details of club: ")
print("3. Press 3 for Update club Details: ")
print("4. Press 4 for Delete club Details: ")
print("5. Press 5 for Exit: ")
choice=int(input("Enter Your Choice 1 or 2 or 3 or 4 or 5: "))
if(choice==1):
cid=int(input("Enter club Id: "))
cname=input("Enter club Name: ")
city=input("Enter club city: ")
mycursor.execute("insert into club values(%s,%s,%s)",(cid,cname,city))
con.commit()
elif(choice==2):

44 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

mycursor.execute("select * from club")


myclubs=mycursor.fetchall()
for x in myclubs:
print(x)
elif(choice==3):
cid=int(input("Enter the club id for update: "))
cname=input("Enter club New Name: ")
city=input("Enter club New city: ")

mycursor.execute("update club set cname=%s,city=%s where


cid=%s",(cname,city,cid))

con.commit()
elif(choice==4):
cid=int(input("Enter the club id for delete: "))
mycursor.execute("delete from club where cid=%s",(cid,))
con.commit()
elif(choice==5):
break
else:
print("Wrong Choice")
c=input("Press 'y' for continue and 'n' for exit: ")

OUTPUT:

1. Press 1 for add new club:


2. Press 2 for Show the details of club:
3. Press 3 for Update club Details:
4. Press 4 for Delete club Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 1
Enter club Id: 101
Enter club Name: C1

45 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Enter club city: Delhi


Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new club:
2. Press 2 for Show the details of club:
3. Press 3 for Update club Details:
4. Press 4 for Delete club Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 1
Enter club Id: 102
Enter club Name: C2
Enter club city: Noida
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new club:
2. Press 2 for Show the details of club:
3. Press 3 for Update club Details:
4. Press 4 for Delete club Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(101, 'C1', 'Delhi')
(102, 'C2', 'Noida')
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new club:
2. Press 2 for Show the details of club:
3. Press 3 for Update club Details:
4. Press 4 for Delete club Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 3
Enter the club id for update: 102
Enter club New Name: C2Z
Enter club New city: Noida
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new club:
2. Press 2 for Show the details of club:

46 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

3. Press 3 for Update club Details:


4. Press 4 for Delete club Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(101, 'C1', 'Delhi')
(102, 'C2Z', 'Noida')
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new club:
2. Press 2 for Show the details of club:
3. Press 3 for Update club Details:
4. Press 4 for Delete club Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 4
Enter the club id for delete: 102
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new club:
2. Press 2 for Show the details of club:
3. Press 3 for Update club Details:
4. Press 4 for Delete club Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(101, 'C1', 'Delhi')
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new club:
2. Press 2 for Show the details of club:
3. Press 3 for Update club Details:
4. Press 4 for Delete club Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 5

47 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Practical No - 23: Write a menu driven program to demonstrate add,


display, update, delete and exit. Performed on a table student containing
(sid, sname, course) through python-MySql connectivity.

import mysql.connector
con=mysql.connector.connect(host="localhost",username="root",passwd="root")
mycursor=con.cursor()
mycursor.execute("create database if not exists spg")
mycursor.execute("use spg")

mycursor.execute("create table if not exists Student (sid int primary key, sname varchar(20),
course varchar(20))")

c="y"
while(c=="y" or c=="Y"):
print("1. Press 1 for add new Student: ")
print("2. Press 2 for Show the details of Students: ")
print("3. Press 3 for Update Student Details: ")
print("4. Press 4 for Delete Student Details: ")
print("5. Press 5 for Exit: ")
choice=int(input("Enter Your Choice 1 or 2 or 3 or 4 or 5: "))
if(choice==1):
sid=int(input("Enter Student Id: "))
sname=input("Enter Student Name: ")
course=input("Enter Student Course: ")
mycursor.execute("insert into Student values(%s,%s,%s)",(sid,sname,course))
con.commit()
elif(choice==2):
mycursor.execute("select * from Student")
mystudents=mycursor.fetchall()
for x in mystudents:
print(x)
elif(choice==3):

48 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

sid=int(input("Enter the Student id for update: "))


sname=input("Enter Student New Name: ")
course=input("Enter Student New Course: ")

mycursor.execute("update Student set sname=%s,course=%s where


sid=%s",(sname,course,sid))

con.commit()
elif(choice==4):
cid=int(input("Enter the Student id for delete: "))
mycursor.execute("delete from Student where sid=%s",(sid,))
con.commit()
elif(choice==5):
break
else:
print("Wrong Choice")
c=input("Press 'y' for continue and 'n' for exit: ")

OUTPUT:

1. Press 1 for add new Student:


2. Press 2 for Show the details of Students:
3. Press 3 for Update Student Details:
4. Press 4 for Delete Student Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 1
Enter Student Id: 101
Enter Student Name: Shiva
Enter Student Course: BCA
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Student:
2. Press 2 for Show the details of Students:
3. Press 3 for Update Student Details:

49 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

4. Press 4 for Delete Student Details:


5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 1
Enter student Id: 102
Enter Student Name: Saanvi
Enter Student Course: B.Tech.
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Student:
2. Press 2 for Show the details of Students:
3. Press 3 for Update Student Details:
4. Press 4 for Delete Student Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5:
(1, 'Ram', 'BCA')
(3, 'Sam', 'MCA')
(101, 'Shiva', 'BCA')
(102, 'Saanvi', 'B.Tech.')
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Student:
2. Press 2 for Show the details of Students:
3. Press 3 for Update Student Details:
4. Press 4 for Delete Student Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 3
Enter the Student id for update: 101
Enter Student New Name: Shiva
Enter Student New Course: MBA
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Student:
2. Press 2 for Show the details of Students:
3. Press 3 for Update Student Details:
4. Press 4 for Delete Student Details:
5. Press 5 for Exit:

50 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Enter Your Choice 1 or 2 or 3 or 4 or 5: 2


(1, 'Ram', 'BCA')
(3, 'Sam', 'MCA')
(101, 'Shiva', 'MBA')
(102, 'Saanvi', 'B.Tech.')
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Student:
2. Press 2 for Show the details of Students:
3. Press 3 for Update Student Details:
4. Press 4 for Delete Student Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 4
Enter the Student id for delete: 3
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Student:
2. Press 2 for Show the details of Students:
3. Press 3 for Update Student Details:
4. Press 4 for Delete Student Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(1, 'Ram', 'BCA')
(3, 'Sam', 'MCA')
(102, 'Saanvi', 'B.Tech.')
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Student:
2. Press 2 for Show the details of Students:
3. Press 3 for Update Student Details:
4. Press 4 for Delete Student Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 5

51 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Practical No - 24: Write a menu driven program to demonstrate add,


display, update, delete and exit. Performed on a table movie containing
(mid, mname, rating) through python-MySql connectivity.

import mysql.connector
con=mysql.connector.connect(host="localhost",username="root",passwd="root")
mycursor=con.cursor()
mycursor.execute("create database if not exists spg")
mycursor.execute("use spg")

mycursor.execute("create table if not exists movie (mid int primary key,mname


varchar(20),rating float(5,2))")

c="y"
while(c=="y" or c=="Y"):
print("1. Press 1 for add new movie: ")
print("2. Press 2 for Show the details of movie: ")
print("3. Press 3 for Update movie Details: ")
print("4. Press 4 for Delete movie Details: ")
print("5. Press 5 for Exit: ")
choice=int(input("Enter Your Choice 1 or 2 or 3 or 4 or 5: "))
if(choice==1):
mid=int(input("Enter movie Id: "))
mname=input("Enter movie Name: ")
rating=float(input("Enter movie rating: "))
mycursor.execute("insert into movie values(%s,%s,%s)",(mid,mname,rating))
con.commit()
elif(choice==2):
mycursor.execute("select * from movie")
mymovies=mycursor.fetchall()
for x in mymovies:
print(x)
elif(choice==3):

52 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

mid=int(input("Enter the movie id for update: "))


mname=input("Enter movie New Name: ")
rating=float(input("Enter movie New Rating: "))

mycursor.execute("update movie set mname=%s,rating=%s where


mid=%s",(mname,rating,mid))

con.commit()
elif(choice==4):
mid=int(input("Enter the movie id for delete: "))
mycursor.execute("delete from movie where mid=%s",(mid,):
con.commit()
elif(choice==5):
break
else:
print("Wrong Choice")
c=input("Press 'y' for continue and 'n' for exit: ")

OUTPUT:

1. Press 1 for add new movie:


2. Press 2 for Show the details of movie:
3. Press 3 for Update movie Details:
4. Press 4 for Delete movie Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 1
Enter movie Id: 101
Enter movie Name: Ghatak
Enter movie rating: 4.6
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new movie:
2. Press 2 for Show the details of movie:
3. Press 3 for Update movie Details:

53 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

4. Press 4 for Delete movie Details:


5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(11, 'Gadar', 5.0)
(13, 'Indian', 4.9)
(101, 'Ghatak', 4.6)
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new movie:
2. Press 2 for Show the details of movie:
3. Press 3 for Update movie Details:
4. Press 4 for Delete movie Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 3
Enter the movie id for update: 101
Enter movie New Name: Ghatak
Enter movie New Rating: 4.8
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new movie:
2. Press 2 for Show the details of movie:
3. Press 3 for Update movie Details:
4. Press 4 for Delete movie Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(11, 'Gadar', 5.0)
(13, 'Indian', 4.9)
(101, 'Ghatak', 4.8)
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new movie:
2. Press 2 for Show the details of movie:
3. Press 3 for Update movie Details:
4. Press 4 for Delete movie Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 4

54 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Enter the movie id for delete: 101


Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new movie:
2. Press 2 for Show the details of movie:
3. Press 3 for Update movie Details:
4. Press 4 for Delete movie Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(11, 'Gadar', 5.0)
(13, 'Indian', 4.9)
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new movie:
2. Press 2 for Show the details of movie:
3. Press 3 for Update movie Details:
4. Press 4 for Delete movie Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 5

Practical No - 25: Write a menu driven program to demonstrate add,


display, update, delete and exit. Performed on a table Employee
containing (eid, ename, salary) through python-MySql connectivity.

import mysql.connector
con=mysql.connector.connect(host="localhost",username="root",passwd="root")
mycursor=con.cursor()
mycursor.execute("create database if not exists spg")
mycursor.execute("use spg")

mycursor.execute("create table if not exists Employee (eid int primary key, ename varchar(20),
salary float(8,2))")

c="y"
while(c=="y" or c=="Y"):

55 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

print("1. Press 1 for add new Employee: ")


print("2. Press 2 for Show the details of Employees: ")
print("3. Press 3 for Update Employee Details: ")
print("4. Press 4 for Delete Employee Details: ")
print("5. Press 5 for Exit: ")
choice=int(input("Enter Your Choice 1 or 2 or 3 or 4 or 5: "))
if(choice==1):
eid=int(input("Enter Employee Id: "))
ename=input("Enter Employee Name: ")
salary=input("Enter Employee Salary: ")
mycursor.execute("insert into Employee values(%s,%s,%s)",(eid,ename,salary))
con.commit()
elif(choice==2):
mycursor.execute("select * from Employee")
myemp=mycursor.fetchall()
for x in myemp:
print(x)
elif(choice==3):
eid=int(input("Enter the Employee id for update: "))
ename=input("Enter Employee New Name: ")
salary=input("Enter Employee New Salary: ")

mycursor.execute("update Employee set ename=%s,salary=%s where


eid=%s",(ename,salary,eid))

con.commit()
elif(choice==4):
eid=int(input("Enter the Employee id for delete: "))
mycursor.execute("delete from Employee where eid=%s",(eid,))
con.commit()
elif(choice==5):
break
else:

56 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

print("Wrong Choice")
c=input("Press 'y' for continue and 'n' for exit: ")

OUTPUT:

1. Press 1 for add new Employee:


2. Press 2 for Show the details of Employees:
3. Press 3 for Update Employee Details:
4. Press 4 for Delete Employee Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 1
Enter Employee Id: 101
Enter Employee Name: S P
Enter Employee Salary: 234567
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Employee:
2. Press 2 for Show the details of Employees:
3. Press 3 for Update Employee Details:
4. Press 4 for Delete Employee Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 1
Enter Employee Id: 102
Enter Employee Name: Shubham
Enter Employee Salary: 123456
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Employee:
2. Press 2 for Show the details of Employees:
3. Press 3 for Update Employee Details:
4. Press 4 for Delete Employee Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 1
Enter Employee Id: 103
Enter Employee Name: Saanvi

57 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Enter Employee Salary: 134567


Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Employee:
2. Press 2 for Show the details of Employees:
3. Press 3 for Update Employee Details:
4. Press 4 for Delete Employee Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(101, 'S P ', 234567.0)
(102, 'Shubham', 123456.0)
(103, 'Saanvi', 134567.0)
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Employee:
2. Press 2 for Show the details of Employees:
3. Press 3 for Update Employee Details:
4. Press 4 for Delete Employee Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 3
Enter the Employee id for update: 102
Enter Employee New Name: Shubham Bhardwaj
Enter Employee New Salary: 174568
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Employee:
2. Press 2 for Show the details of Employees:
3. Press 3 for Update Employee Details:
4. Press 4 for Delete Employee Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(101, 'S P ', 234567.0)
(102, 'Shubham Bhardwaj', 174568.0)
(103, 'Saanvi', 134567.0)
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Employee:

58 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

2. Press 2 for Show the details of Employees:


3. Press 3 for Update Employee Details:
4. Press 4 for Delete Employee Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 4
Enter the Employee id for delete: 101
Press 'y' for continue and 'n' for exit: y
1. Press 1 for add new Employee:
2. Press 2 for Show the details of Employees:
3. Press 3 for Update Employee Details:
4. Press 4 for Delete Employee Details:
5. Press 5 for Exit:
Enter Your Choice 1 or 2 or 3 or 4 or 5: 2
(102, 'Shubham Bhardwaj', 174568.0)
(103, 'Saanvi', 134567.0)
Press 'y' for continue and 'n' for exit: n

MYSQL QUERIES

Q-1 Create a Database.

To create a database we use create database query.


Syntax:
Create database database_name;
59 Suraj Kumar GSBV(BURARI)
CS PRACTICLE FILE SESSION 2024-25 CLASS 12

To check/show the already created databases use the following


Query.
Show databases;

Q-2 - To create a student table with the student id, class, section, gender,name,
dob, and marks as attributes where the student id is the primary key.
Ans - Primary Key:
Primary key is a constraint of an attribute which cannot be NULL or duplicate.
Only one primary key is allowed in a table.
To create a new table we use create table query.
Syntax:
Create table table_name(col_name1 type primary key, col_name2 type, ……..);

60 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q-3 - To insert the details of at least 10 students in the student table.

To insert the records in the table we use insert into query


Insert into table_name values(col1_value, col2_value, ……..);

61 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q-4 - To delete the details of a particular student in the student table.


To delete the specific record from the table use delete command/query.
Syntax:
Delete from table_name where condition;
Note: If we don’t use where clause It delete all the records one by one from the
table.

Q- 5 - To increase the marks by 5% for those students who are scoring marks
more than 30.
Update:
Update is a SQL query used to update/change/modify the record of a table.
Syntax:
update tablename set col_name=value, col_name=value,... where condition;

62 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q-6 - To display the entire content of the table.

Q-7 - To display student_id, name and marks of those students who are scoring
marks more than 30.

63 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q-8 - To find the average marks from the student table.


Aggregate Function:
5 Aggregate function in SQL:
1. SUM() : Find the sum of the values of specific column
2. MAX() : Find the maximum value from the specific column
3. MIN() : Find the minimum value from the specific column
4. AVG() : Find the average of all values from the specific column
5. COUNT() : Count the value from the specific column

Q-9 - To find the number of students, who are from section ‘A’.

64 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q-10 - To add a new column email in the student table with appropriate data
type.

65 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q-11 - To add the email id’s of each student in the previously created email
column.

Q-12 - To display the information of all the students, whose name starts with
‘S’

66 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q-13 - To display the student_id, name, dob of those students who are born
between ‘2005-01-01’ and ‘2005-12-31’.

Q- 14 - To display the student_id, name, dob, marks, email of male students in


ascending order of their name.

67 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q-15 - To display the student_id, gender, name, dob, marks, email of students
in descending order of their marks.

Q-16 - To display the unique section name from the student table.

68 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q – 17: Create a student table with student id, name and marks as attribute,
where the student id is the primary key.

Q – 18: Insert the details of 5 students in the student table.

69 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q –19: Delete the details of a student in the student table.

Q –20: Use the Select command to get the details of the students with marks
more than 30.

70 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q-21 : Shiva, a student of class XII, created a table “CLASS”. Grade is one of the
columns of this table. Write the SQL query to find the details of students whose
grade have not been entered.

Q-23 : Write the difference between drop, delete and truncate command with
example.
Drop
Drop is a DDL (Data Definition Language) command of SQL.
Drop is used to remove an object completely just like remove database, table, view, index etc.
Syntax:
DROP object object_name
Examples:
DROP TABLE table_name;
table_name: Name of the table to be deleted.
DROP DATABASE database_name;
database_name: Name of the database to be deleted.

Delete
Delete is a DML (Data Manipulation Language) command of SQL.
Delete is used to remove one or more rows from a table, view, index etc. We can use where clause with delete
command. Delete remove one row at a time i.e. it remove rows one by one. It will not delete columns or structure of
table.
Syntax:
delete from table_name where condition;
Examples:
delete from table_name;
table_name: Name of the table from which rows will be deleted.
Delete all rows from the table.
71 Suraj Kumar GSBV(BURARI)
CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Truncate
Truncate is a DDL (Data Defination Language) command of SQL.
Truncate is used to remove all rows from a table, view, index etc. We can not use where clause with truncate
command. Truncate remove all rows at once, but it will not delete structure of the table or any object.
Syntax:
delete from table_name where condition;
Examples:
trucate table_name;
table_name: Name of the table from which rows will be deleted.
Delete all rows from the table at once.

Q-24 : Write the sort notes on group by, having and where clause with example.

WHERE Clause
WHERE Clause is used to filter the records/rows from the table. It can be used with SELECT, UPDATE,
DELETE statements.
Select * from employees where salary>25000;

Group by Clause
The GROUP BY clause is used with aggregate functions (MAX, SUM, AVG, COUNT, MIN) to group the
results by one or more columns i.e. The GROUP BY clause is used with the SELECT statement to arrange
required data into groups.

The GROUP BY statement groups rows that have the same values. This Statement is used after the where
clause. This statement is often used with some aggregate function like SUM, AVG, and COUNT etc. to
group the results by one or more columns.

SELECT COUNT (City) AS COUNT_CITIES, City FROM EMPLOYEES GROUP BY City;

Having Clause
Having Clause is like the aggregate function with the GROUP BY clause. The HAVING clause is used
instead of WHERE with aggregate functions. While the GROUP BY Clause group rows that have the
same values into rows. The having clause is used with the where clause in order to find rows with certain
conditions. The having clause is always used after the group by clause.

SELECT COUNT (City) AS COUNT_CITIES, City FROM EMPLOYEES

GROUP BY City HAVING COUNT (City) > 1;

WHERE Clause Having Clause Group By Clause

WHERE Clause is used to filter the HAVING Clause is used to filter The group by clause is used to
records from the table based on record from the groups based on group the data according to
the specified condition. the specified condition. particular column or row.

WHERE Clause can be used HAVING Clause cannot be used Group by can be used without
without GROUP BY Clause without GROUP BY Clause having clause with the select
statement.

WHERE Clause implements in row HAVING Clause implements in It groups the output on basis of
operations column operation some rows or columns.

WHERE Clause cannot contain The having clause can contain It cannot contain aggregate
aggregate function aggregate functions. functions.

72 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12
WHERE Clause is used with single HAVING Clause is used with Group by Clause is a multiple row
row function like UPPER, LOWER multiple row function like SUM, function
etc. COUNT etc

WHERE Clause can be used with HAVING Clause can only be used The GROUP BY clause is used in
SELECT, UPDATE, DELETE with SELECT statement. the SELECT statement.
statement.

WHERE Clause is used before HAVING Clause is used after Group By is used after the Where
GROUP BY Clause GROUP BY Clause clause and before the HAVING
Clause

Q-25 : Write the SQL query to find out the square root of 26.

Q-26 : Shiva is using a table employee. It has following details: Employee (Code,
Name, Salary, DeptCode). Write the SQL query to display maximum salary
department wise.

73 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q-27 : Write the SQL Query to display the difference of highest and lowest salary
of each department having maximum salary greater than 4000.

Q-28 : Write the SQL Query to increase 20% salary ofthe employee whose
experience is more than 5 year of the table Emp(id, name, salary, exp)

74 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q-29 : Write the SQL Query for inner join of two tables Emp(eid, ename, salary,
dept_id) and Dept(dept_id, dname)

Q-30 : Write the SQL Query for full outer join of two tables Emp(eid,
ename,salary,dept_id) and Dept(dept_id, dname)

Q-31 : Write a SQL to Enter 5 Employee data in a single query in the table Emp
(eid, ename, salary, city, dob).

75 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

Q-32 : Display 4 characters extracted from 5th right character onwards from string
‘ABCDEFG’.

Q-33 : Write a query to create a string from the ASCII values 65, 67.3, ‘68.3’.

Q-34 : Display names ‘MR. MODI’ and ‘MR. Sharma’ into lowercase.

Q-35 : How many characters are there in string ‘CANDIDE’.

76 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

77 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

78 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

79 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

80 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

81 Suraj Kumar GSBV(BURARI)


CS PRACTICLE FILE SESSION 2024-25 CLASS 12

82 Suraj Kumar GSBV(BURARI)

You might also like