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