0% found this document useful (0 votes)
5 views2 pages

CBSE SQL Python MySQL Programs

The document provides essential Python MySQL programs for CBSE Class 12, including basic connection setup, creating a table, inserting, fetching, searching, updating, and deleting records in a MySQL database. It demonstrates the use of the mysql.connector library for database operations. Each section includes code snippets for practical implementation.

Uploaded by

Khushi Gurunani
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)
5 views2 pages

CBSE SQL Python MySQL Programs

The document provides essential Python MySQL programs for CBSE Class 12, including basic connection setup, creating a table, inserting, fetching, searching, updating, and deleting records in a MySQL database. It demonstrates the use of the mysql.connector library for database operations. Each section includes code snippets for practical implementation.

Uploaded by

Khushi Gurunani
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

CBSE Class 12 - Python MySQL Programs

(Important)

1. Basic Connection
import [Link]

con = [Link](
host="localhost",
user="root",
password="1234",
database="School"
)

if con.is_connected():
print("Connected successfully")

[Link]()

2. Create Table
cur = [Link]()
[Link]("""
CREATE TABLE Student(
Roll_No INT PRIMARY KEY,
Name VARCHAR(50),
Marks INT
)
""")

3. Insert Record
sql = "INSERT INTO Student VALUES (%s, %s, %s)"
values = (1, "Rahul", 85)
[Link](sql, values)
[Link]()

4. Fetch Records
[Link]("SELECT * FROM Student")
data = [Link]()
for row in data:
print(row)

5. Search Record
[Link]("SELECT * FROM Student WHERE Marks > 80")
for row in cur:
print(row)

6. Update Record
[Link]("UPDATE Student SET Marks = 90 WHERE Roll_No = 1")
[Link]()
7. Delete Record
[Link]("DELETE FROM Student WHERE Roll_No = 1")
[Link]()

You might also like