Submitted in partial fulfillment of AISSCE 2025-26 conducted by C.B.S.E.
Of
“Python + SQL Practical”
Under the guidance of
Mr. Mohammad Shadab
Submitted By,
Student Name: Shubh Dwivedi
Class: XII
Roll No.:
St. Joseph’s Eng. Med. Sr. Sec. School
Station Road, Mahoba
Acknowledgement
Many lives & destinies are destroyed due to the lack of proper guidance,
directions & opportunities. It is in this respect I feel that I am in much better
condition today due to continuous process of motivation & focus provided
by my parents & teachers in general. The process of completion of this
practical was a tedious job & requires care & support at all stages. I would
like to highlight the role played by individuals towards this.
I am very thankful to Fr. Fredrick A, Our Principal for his kind support &
faith in us.
I would like to express my sincere thanks, with a deep sense of gratitude to
my practical guide Mr. Mohammad Shadab for his keen interests in my
practical.
I am also thankful to all visible and invisible hands which helped us to
complete this practical with a feeling of success.
SHUBH DWIVEDI
Certificate
This is to certify that the practical titled “Python + SQL Practicals” submitted
by “Shubh Dwivedi” in partial fulfillment of AISSCE 2025–26 conducted by
C.B.S.E., New Delhi, has been completed under the supervision of Mr.
Mohammad Shadab, Department of Computer Science, at St. Joseph’s English
Medium Senior Secondary School, Station Road, Mahoba.
The above statement made by the candidate is correct to the best of my
knowledge.
Mr. Mohammad Shadab Fr. Fredrick A
Practical Mentor Principal
[H.O.D. Computer Science]
External Examiner
Date: ________________________
Python – Sql Practicals
1. Write a program to connect MYSQL Server and select the database
named “firstdb” . Print a message to confirm a successful connection. If
the database doesn’t exist create it.
Python Code
import [Link]
con = [Link]( host="localhost", user="root",
password="shubh@0987")
cursor = [Link]()
[Link]("CREATE DATABASE IF NOT EXISTS firstdb")
[Link]("USE firstdb")
print("Database created and selected successfully.")
[Link]()
Python Output
2. To write a Python Program to integrate MYSQL with Python by inserting
records to School table and display the records.
(That contain Admission No’ , Name, Class, Height, Weight)
Python Code
import [Link]
con = [Link]( host="localhost", user="root",
password="shubh@0987", database="firstdb"
)
cursor = [Link]()
[Link]("""
CREATE TABLE IF NOT EXISTS School(
AdmissionNo INT PRIMARY KEY, Name VARCHAR(50),
Class VARCHAR(10),
Height FLOAT, Weight FLOAT
) """)
rec = [
(101, "Shubh", "12A", 5.11, 57),
(102, "Arkan", "12A", 5.9, 60),
(103, "Rishi", "12A", 5.7, 100),
(104, "Kartik", "12A",5.6, 55),
(105, "Khushi", "12A", 5.1, 65),
]
[Link]("INSERT INTO School VALUES (%s,%s,%s,%s,%s)", rec)
[Link]()
[Link]("SELECT * FROM School")
data = [Link]()
for row in data:
print(row)
[Link]()
Python Output
SQL Table
3. To write a Python Program to integrate MYSQL with Python to search
an Student using Admission No and display the record if present in
already existing table School, if not display the appropriate message.
Python Code
import [Link]
con = [Link]( host="localhost", user="root",
password="shubh@0987", database="firstdb"
)
cursor = [Link]()
adm = int(input("Enter Admission No: "))
[Link]("SELECT * FROM School WHERE AdmissionNo=%s", (adm,))
row = [Link]()
if row:
print(row)
else:
print("Record not found")
[Link]()
Python Output
Sql Table
4. To write a Python program to integrate MYSQL with Python to delete
student record using Admission No (user input) and then print a
confirming message.
Python Code
import [Link]
con = [Link](
host="localhost",
user="root",
password="shubh@0987",
database="firstdb"
)
cur = [Link]()
adm = int(input("Enter Admission No to delete: "))
[Link]("DELETE FROM School WHERE admno = %s", (adm,))
[Link]()
if [Link] > 0:
print("Student record deleted successfully!")
else:
print("No student found with this Admission Number.")
[Link]()
Python Output
Updated SQL Table
5. To write Queries for the following Questions based on the given
student table: (Fill this D.O.B. by yourself )
i. Write a Query to select distinct Department from STU table.
Sql Code
i. Write a Query to select distinct Department from STU table.
SELECT DISTINCT Dept
FROM STU;
Sql Ouput Table
ii. To show all information about students of History department.
Sql Code
SELECT *
FROM STU
WHERE Department = 'History';
Sql Output Table
iii. Write a Query to list name of female students in Hindi
Department.
Sql Code
SELECT Name
FROM STU
WHERE Dept = 'Hindi' AND Gender = 'F';
Sql Output
iv. Write a query to list the names of those students whose name
have second alphabet 'n' in their names.
Sql Code
SELECT Name
FROM STU
WHERE Name LIKE '_n%';
Sql Output Table
6. Insert following data records into Teachers and Student table Teacher
table info:
Subject table info:
For teacher table:
For Subject table :
a. To display all records from Teacher info table whose work experience is more
than 5 years
b. To display F_ID, Fname, Cname of those teacher info who charged more than
15000 as fees.
c. To display all records Teacher info table order by First Name of the faculty in
descending order
Teacher Table Creation Code:
CREATE TABLE Teacher(
F_ID INT PRIMARY KEY,
Fname VARCHAR(30),
Lname VARCHAR(30),
WorkExp DATE, Salary INT
);
INSERT INTO Teacher VALUES
(102, 'Amit', 'Sharma', '2010-06-01', 12000),
(103, 'Rita', 'Kumar', '2016-03-15', 8000),
(104, 'Sunil', 'Verma', '2008-09-10', 14000),
(105, 'Neha', 'Gupta', '2012-01-20', 11000),
(106, 'Rakesh', 'Patel', '2014-11-05', 10000),
(107, 'Pooja', 'Singh', '2005-02-12', 16000);
Teacher Table :
Subject Table Creation Code:
CREATE TABLE SubjectTbl(
C_ID VARCHAR(10) PRIMARY KEY,
F_ID INT,
Cname VARCHAR(40),
Fees INT
);
INSERT INTO SubjectTbl VALUES
('C21', 102, 'Maths', 40000),
('C22', 106, 'Science', 16000),
('C23', 104, 'English', 8000),
('C24', 106, 'Hindi', 15000),
('C25', 102, 'Physics', 20000),
('C26', 105, 'Chemistry', 6000),
('C27', 107, 'Biology', 4000);
Student Table :
Query 1:
SELECT * FROM Teacher WHERE YEAR(CURDATE()) - YEAR(WorkExp) > 5;
SQL Table
Query 2:
SELECT Teacher.F_ID, [Link], [Link]
FROM Teacher, SubjectTbl
WHERE Teacher.F_ID = SubjectTbl.F_ID AND [Link] > 15000;
SQL Table
Query 3:
SELECT * FROM Teacher ORDER BY Fname DESC;
SQL Table
7. To write Queries for the following Questions :
a. Write a query to display cube of 5.
b. Write a query to display the number 563.854741 rounding off to
the next hundred.
c. Write a query to display "put" from the word "Computer".
d. Write a query to display today's date into [Link] format.
e. Write a query to display 'DIA' from the word "MEDIA"
Query 1:
SELECT POWER(5,3);
SQL Table
Query 2:
SELECT ROUND(563.854741, -2);
SQL Table
Query 3:
SELECT SUBSTR('Computer',4,3);
SQL Table
Query 4:
SELECT DATE_FORMAT(CURDATE(), '%d.%m.%Y');
SQL Table
Query 5:
SELECT SUBSTR('MEDIA',3,3);
SQL Table
8. Create a table and then write the query to display name, age, and
marks(aggregate) of students whose age is greater than or equal to 16
from table student.
Table Creation Code:
CREATE TABLE student(
name VARCHAR(50),
age INT,
marks INT
);
INSERT INTO student VALUES
('Kavya', 17, 85),
('Neha', 16, 90),
('Reena', 18, 80),
('Simran', 15, 75),
('Kavita', 16, 88);
SQL Table
Query
SELECT name, age, marks
FROM student
WHERE age >= 16;
SQL Table
9. Add the following data in the table (EMPLOYEE) as instructed
(i)Populate table with first record mentioning the column list in
the insert clause.
(ii)Populate table with next two records without mentioning the
column list in the insert clause.
(iii) Populate table with 4th record and enter only ID and
First_Name.
(iv) Populate table with 5th recorded and enter ID, User_ID, and
Last_Name only.
Table Creation Code:
CREATE TABLE EMPLOYEE(
Id INT PRIMARY KEY,
F_Name VARCHAR(30),
L_Name VARCHAR(30),
User_ID VARCHAR(30),
Salary INT
);
Query 1:
INSERT INTO EMPLOYEE (Id, F_Name, L_Name, User_ID, Salary)
VALUES (1,'Dim','Joseph','Jdim',5000);
SQL Table
Query 2:
INSERT INTO EMPLOYEE
VALUES (2,'Jagannath','Mishra','jnmishra',4000);
INSERT INTO EMPLOYEE
VALUES (3,'Siddharth','Mishra','smishra',8000);
SQL Table
Query 3:
INSERT INTO EMPLOYEE (Id, F_Name)
VALUES (4,'Shankar');
SQL Table
Query 4:
INSERT INTO EMPLOYEE (Id, User_ID, L_Name)
VALUES (5,'bgautam','Buddha');
SQL Table
10. Consider the following movie table and write the SQL queries based on it:
a. Display all the information from the movie table.
b. List business done by the movies showing only MovieID, MovieName
and Total_Earning. Total_Earning to be calculated as the sum of Product
Cost and BusinessCost.
c. List the different categories of movies.
d. Find the net profit of each movie showing its ID, Name and Net
Profit. Net profit is to be calculated as the difference between
BusinessCost and ProductCost.
e. List MoviesID, MovieName and Cost of all movies with Product Cost
greater than 10,000 and less than 1,00,000.
f. List details of all movies which fall in the category of Comedy or
Action
g. List details of all movies which have not been released yet.
Table Creation Code:
CREATE TABLE Movie(
MovieID VARCHAR(5) PRIMARY KEY,
MovieName VARCHAR(30),
Category VARCHAR(20),
ReleaseDate VARCHAR(15),
ProductionCost INT, BusinessCost INT
);
INSERT INTO Movie VALUES
('001', 'Hindi Mov', 'Musical', '2018/04/23', 124500, 130000),
('002', 'Tamil Mov', 'Action', '2016/05/17', 112000, 118000),
('003', 'English Mov', 'Horror', '2017/08/06', 245000, 360000),
('004', 'Bengali Mov', 'Adventure', '2017/01/04', 72000, 100000),
('005', 'Telgu Mov', 'Action', '-', 100000, NULL),
('006', 'Punjabi Mov', 'Comedy', '-', 30500, NULL);
Query 1:
SELECT * FROM Movie;
SQL Table
Query 2:
SELECT MovieID, MovieName, (ProductionCost + BusinessCost)
AS Total_Earning
FROM Movie;
SQL Table
Query 3:
SELECT DISTINCT Category FROM Movie;
SQL Table
Query 4:
SELECT MovieID, MovieName, (BusinessCost - ProductionCost)
AS NetProfit
FROM Movie;
SQL Table
Query 5:
SELECT MovieID, MovieName
FROM Movie
WHERE ProductionCost BETWEEN 10000 AND 100000;;
SQL Table
Query 6:
SELECT * FROM Movie WHERE Category IN ('Action','Comedy');
SQL Table
Query 7:
SELECT * FROM Movie WHERE ReleaseDate IS NULL;
SQL Table