Python_sql_project class 12th
Python_sql_project class 12th
I would like to extend my heartfelt gratitude to my Computer Science teacher, [Teacher's Name], for their
invaluable guidance, encouragement, and support throughout the course of this project. Their expertise and
insights have been instrumental in shaping my understanding of the subject and completing this project
successfully. I am deeply grateful for their patience and constant motivation, which helped me overcome
challenges during the project development.
I would also like to express my sincere thanks to my parents, whose unwavering support and encouragement
have been my driving force. Their belief in my abilities has always inspired me to strive for excellence.
Furthermore, I am thankful to my friends for their assistance, feedback, and moral support, which greatly
contributed to the smooth execution of this project.
Finally, I am grateful to all those who directly or indirectly supported me in making this project a success. This
experience has been a significant learning journey, and I am deeply appreciative of the opportunities it has
provided.
CERTIFICATE
This is to certify that [Your Name], a student of Class XII, has successfully completed the Computer Science
project titled "Python - SQL Connectivity" during the academic year 2024-25. This project has been
conducted in accordance with the guidelines and requirements prescribed by the Central Board of Secondary
Education (CBSE).
The project reflects [Your Name]’s dedication, creativity, and understanding of the topic. It demonstrates their
ability to apply theoretical knowledge to practical scenarios, showcasing a thorough exploration of Python-SQL
connectivity and its implementation.
Under my guidance, [Your Name] has diligently worked on every aspect of the project, from researching the
topic to executing and documenting the results. The efforts and commitment displayed by [Your Name] are
commendable and worthy of appreciation.
Signature
(Subject Teacher)
INDEX
1. Acknowledgment
2. Certificate
3. Introduction to Python-SQL Connectivity
4. Objectives
5. Prerequisites
6. Project Description
7. Modules and Functions
8. SQL Table Design
9. Python Code
10. Screenshots of Output
11. Conclusion
12. Bibliography
Python is a powerful and versatile programming language known for its simplicity and readability. It has
become one of the most popular languages for various applications, from web development to data analysis.
One of its key strengths is its ability to interact with databases, which is essential for building dynamic
applications that require the storage, retrieval, and manipulation of data. Python can connect to databases using
libraries such as mysql.connector, sqlite3, SQLAlchemy, and others, making it an ideal choice for developers
looking to integrate database functionality into their applications.
SQL, or Structured Query Language, is the standard language used to manage and manipulate relational
databases. SQL allows developers to define, manipulate, and query data stored in relational databases, making it
an essential skill for anyone working with databases. It provides commands for creating and modifying database
structures (like tables and indexes), inserting, updating, and deleting records, and querying data using complex
conditions.
The ability to integrate Python with SQL opens up a wide range of possibilities for developers. Python-SQL
connectivity allows Python applications to interact with databases in a seamless and efficient manner. By using
Python's built-in libraries, developers can perform operations such as retrieving data from the database,
inserting new records, updating existing records, and deleting records, all from within their Python code. This is
particularly useful in various real-world applications, such as inventory management systems, student
databases, banking applications, and more, where data needs to be stored and retrieved dynamically.
This project focuses on establishing a connection between Python and an SQL database, specifically MySQL. It
demonstrates how to perform basic CRUD (Create, Read, Update, Delete) operations on a database using
Python, providing a solid foundation for anyone looking to work with Python and databases in real-world
applications. By understanding Python-SQL connectivity, developers can create robust applications that manage
and manipulate data effectively.
Objectives
1. To understand the process of connecting Python with SQL and establish a seamless communication
channel between Python programs and SQL databases.
2. To explore the various libraries and modules, such as mysql.connector, that facilitate the interaction
between Python and SQL databases.
3. To learn how to create and design SQL tables within a database using Python, ensuring data is organized
efficiently for future operations.
4. To understand and implement CRUD (Create, Read, Update, Delete) operations in Python for managing
data in a relational database.
5. To develop a Python program that can interact with a MySQL database, performing basic tasks like
inserting, retrieving, updating, and deleting records.
6. To gain hands-on experience with SQL commands such as SELECT, INSERT INTO, UPDATE, and
DELETE within Python applications.
7. To enhance skills in error handling and troubleshooting while working with database connections in
Python.
8. To develop an understanding of database security practices, such as using parameterized queries to
prevent SQL injection attacks when interacting with a database in Python.
9. To understand the importance of data integrity and consistency while working with databases in Python
and ensuring that operations follow best practices.
10. To apply Python-SQL connectivity in real-world projects, such as creating applications for inventory
management, student information systems, or simple customer databases.
11. To analyze and optimize database queries for better performance and faster retrieval of data in Python
applications.
12. To build a practical understanding of how database management systems work and how Python can be
used to efficiently manage data.
Prerequisites
This section outlines the tools and knowledge required to execute the project.
Project Description
The project demonstrates how to connect a Python program with a MySQL database to perform CRUD
operations.
Modules Used:
This section defines the structure of the SQL table used in the project.
Table Name: students
Columns and Constraints:
Python Code
import mysql.connector
def connect_to_database():
return mysql.connector.connect(
host="localhost",
user="root",
password="your_password",
database="school"
)
def create_table():
db = connect_to_database()
cursor = db.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS students (
roll_no INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
class VARCHAR(5) NOT NULL,
marks FLOAT NOT NULL
)
""")
db.commit()
db.close()
def view_records():
db = connect_to_database()
cursor = db.cursor()
cursor.execute("SELECT * FROM students")
for row in cursor.fetchall():
print(row)
db.close()
def update_record(roll_no, marks):
db = connect_to_database()
cursor = db.cursor()
cursor.execute("UPDATE students SET marks = %s WHERE roll_no = %s", (marks, roll_no))
db.commit()
db.close()
def delete_record(roll_no):
db = connect_to_database()
cursor = db.cursor()
cursor.execute("DELETE FROM students WHERE roll_no = %s", (roll_no,))
db.commit()
db.close()
# Example Usage
create_table()
insert_record(1, "John Doe", "12A", 85.5)
view_records()
update_record(1, 90)
view_records()
delete_record(1)
view_records()
Screenshots of Output
Conclusion
Through the completion of this project, I have gained valuable, practical knowledge of integrating Python with
MySQL, which has significantly enhanced my understanding of how databases work and how they can be
managed efficiently using Python. This project not only provided hands-on experience in connecting Python to
a MySQL database but also helped me understand the inner workings of SQL operations and their application in
real-world scenarios.
I learned how to perform key database operations such as creating tables, inserting records, retrieving data,
updating existing information, and deleting records. These fundamental CRUD (Create, Read, Update, Delete)
operations are essential in developing robust applications that manage data effectively. Additionally, I gained
insight into handling database connections, managing errors, and ensuring data integrity, which are crucial
aspects when working with databases in production environments.
Working with Python-SQL connectivity allowed me to better understand the importance of a well-structured
database and how data can be dynamically manipulated and retrieved within an application. This project also
exposed me to best practices such as parameterized queries to avoid SQL injection attacks, enhancing the
security of my applications.
By implementing these concepts, I now feel confident in utilizing Python to build applications that require
backend database interactions. The skills and knowledge acquired during this project will undoubtedly aid me in
future endeavors, especially when working on more complex systems that require database management.
Overall, this project has not only strengthened my technical skills but also given me a deeper appreciation for
the seamless integration between programming languages like Python and databases like MySQL.