IP Project for Class 11: Python + SQL
This document outlines an IP Project for Class 11 students integrating Python and SQL. The project
aims to demonstrate CRUD operations using Python as the frontend and SQL as the backend
database.
Objectives
- Understand how to integrate Python with SQL.
- Perform CRUD (Create, Read, Update, Delete) operations.
- Develop problem-solving and coding skills.
Requirements
- Python 3.x
- MySQL Server
- MySQL Connector for Python
Project Outline
1. **Database Design:**
- Create a database named `school`.
- Design a table `students` with the following fields:
- `id` (INT, Primary Key, Auto Increment)
- `name` (VARCHAR(50))
- `age` (INT)
- `class` (VARCHAR(10))
2. **Python Code:**
- Connect to the MySQL database using MySQL Connector.
- Implement CRUD operations:
- Insert new student records.
- Fetch and display all student records.
- Update a student's details.
- Delete a student's record.
3. **Execution:**
- Run the Python script and perform operations.
Sample Code
import mysql.connector
# Connect to MySQL Database
conn = mysql.connector.connect(
host="localhost",
user="root",
password="password",
database="school"
cursor = conn.cursor()
# Insert Data
cursor.execute("INSERT INTO students (name, age, class) VALUES (%s, %s, %s)", ('John
Doe', 15, '10A'))
conn.commit()
# Fetch Data
cursor.execute("SELECT * FROM students")
for row in cursor.fetchall():
print(row)
conn.close()