0% found this document useful (0 votes)
19 views4 pages

Python SQL Connectivity for CBSE XII

The document contains practical programs for Python-SQL connectivity, specifically for creating a database and table, inserting records, displaying records, and updating records in a MySQL database. Each program is provided with code snippets using the mysql.connector library to interact with a 'school' database. The examples demonstrate basic database operations such as creation, insertion, selection, and updating of student records.

Uploaded by

hsjdbwk.mmm
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)
19 views4 pages

Python SQL Connectivity for CBSE XII

The document contains practical programs for Python-SQL connectivity, specifically for creating a database and table, inserting records, displaying records, and updating records in a MySQL database. Each program is provided with code snippets using the mysql.connector library to interact with a 'school' database. The examples demonstrate basic database operations such as creation, insertion, selection, and updating of student records.

Uploaded by

hsjdbwk.mmm
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 XII – Computer Science (Python)

Practical File

Python–SQL Connectivity Programs

Program 1: Create Database and Table

Program:
import [Link]

con = [Link](host='localhost', user='root', password='root')


cur = [Link]()
[Link]("CREATE DATABASE school")
[Link]("USE school")
[Link]("CREATE TABLE student(roll INT, name VARCHAR(20), marks INT)")
[Link]()
Program 2: Insert Records into Table

Program:
import [Link]

con = [Link](host='localhost', user='root', password='root', database='school')


cur = [Link]()
[Link]("INSERT INTO student VALUES (1,'Aman',85)")
[Link]("INSERT INTO student VALUES (2,'Riya',90)")
[Link]()
[Link]()
Program 3: Display Records from Table

Program:
import [Link]

con = [Link](host='localhost', user='root', password='root', database='school')


cur = [Link]()
[Link]("SELECT * FROM student")
data = [Link]()
for row in data:
print(row)
[Link]()
Program 4: Update Marks using Python-SQL

Program:
import [Link]

con = [Link](host='localhost', user='root', password='root', database='school')


cur = [Link]()
[Link]("UPDATE student SET marks=95 WHERE roll=1")
[Link]()
[Link]()

You might also like