0% found this document useful (0 votes)
124 views5 pages

Python Database Application Guide

This document discusses designing database applications in Python to create, search, and modify records in a database. It includes code samples to create a database, search records in a table, add new records, delete records, and update existing records. The code connects to a MySQL database called "Academy" and performs operations on a table called "student" which has fields for student ID and name. The output of running the code is not shown.
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)
124 views5 pages

Python Database Application Guide

This document discusses designing database applications in Python to create, search, and modify records in a database. It includes code samples to create a database, search records in a table, add new records, delete records, and update existing records. The code connects to a MySQL database called "Academy" and performs operations on a table called "student" which has fields for student ID and name. The output of running the code is not shown.
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

Kriti M.

Doongurse College Python Practical

10-a) Design the database applications for the following:


Aim: Design a simple database application that stores the records and retrieve the
same.
#Creating a database:
CODE:
import [Link]
mydb=[Link](host='localhost',user='root',password='12345678')
mycursor = [Link]()
[Link]("CREATE DATABASE Academy")
[Link]("SHOW DATABASES")
for x in mycursor:
print(x)

OUTPUT:

[Link] Roll No:-82


Kriti [Link] College Python Practical

10-b) Design a database application to search the specified record from the
database.
CODE:
import [Link]
mydb = [Link](
host='localhost',
user='root',
password='12345678',
database='academy')
mycursor = [Link]()
[Link]("SELECT * FROM student")
myresult = [Link]()
for x in myresult:
print(x)

OUTPUT:

[Link] Roll No:-82


Kriti [Link] College Python Practical

10-c) Design a database application to that allows the user to add, delete and
modify the records.
i) ADDING A RECORD TO EXISTING RECORDS:
CODE:
import [Link]
mydb = [Link](
host='localhost',
user='root',
password='12345678',
database='academy')
mycursor = [Link]()
a ="INSERT INTO student (student_id, student_name) VALUES (%s, %s)"
b = [("7", "Ramesh")]
[Link](a, b)
[Link]()
print([Link], "was inserted.")

OUTPUT:

[Link] Roll No:-82


Kriti [Link] College Python Practical

ii) DELETING A RECORD FROM EXISTING RECORDS:


CODE:
import [Link]
mydb = [Link](
host='localhost',
user='root',
password='12345678',
database='academy')
mycursor = [Link]()
a ="DELETE FROM student WHERE student_name = 'Ramesh'"
[Link](a)
[Link]()
print([Link], "record(s) deleted")

OUTPUT:

[Link] Roll No:-82


Kriti [Link] College Python Practical

iii) UPDATING A RECORD FROM EXISTING RECORD:


CODE:
import [Link]
mydb = [Link](
host='localhost',
user='root',
password='12345678',
database='academy')
mycursor = [Link]()
a ="UPDATE student SET student_name='Sachin' WHERE
student_name='Rahul'"
[Link](a)
[Link]()
print([Link], "record(s) affected")

OUTPUT:

[Link] Roll No:-82

You might also like