02/07/2025
1.)Write the python mySQL connectivity program to create a database named
"Infomatics"
access the same database and also display the list of existing databases.
import pymysql
p=[Link](host="localhost",user="root",passwd="admin")
m=[Link]()
[Link]('create database infomatics')
[Link]('use infomatics')
[Link]('show databases')
for i in m:
print(i)
2.)Write the python mySQL connectivity program to access the database"infomatics"
and also create a
table name "product" with the following attributes.
Pid-char(5)
Pname-varchar(15)
import pymysql
p=[Link](host="localhost",user="root",passwd="admin")
m=[Link]()
[Link]('use infomatics')
[Link]('create table product(pid char(5),pname varchar(15))')
[Link]('show tables')
for i in m:
print(i)
3.)Write the python mySQL connectivity program to add new column DOE-date
import pymysql
p=[Link](host="localhost",user="root",passwd="admin")
m=[Link]()
[Link]('use infomatics')
[Link]('alter table product add DOE date')
[Link]('desc product')
for i in m:
print(i)
4.)Write the python mySQL connectivity program to add a column price
of int datatype after the column pname.
import pymysql
p=[Link](host="localhost",user="root",passwd="admin")
m=[Link]()
[Link]('use infomatics')
[Link]('alter table product add price int after pname')
[Link]('desc product')
for i in m:
print(i)
5.)Write the python script to insert values in all columns of a [Link] also
display
the records from the relation named "product".
import pymysql
p=[Link](host="localhost",user="root",passwd="admin")
m=[Link]()
[Link]('use infomatics')
[Link]("insert into product values ('P001','ABC',999,'2025-07-04'),
('P002','XYZ',499,'2024-05-08'),('P003','DEF',799,'2023-09-30')")
[Link]("select * from product")
[Link]()
for i in m:
print(i)
6.)Write the python script to update all price of the product by 80.
import pymysql
p=[Link](host="localhost",user="root",passwd="admin")
m=[Link]()
[Link]('use infomatics')
[Link]("update product set price=price+80")
[Link]("select * from product")
[Link]()
for i in m:
print(i)
7.)Parameterised Query-(f%v)
import pymysql as a
b=[Link](host="localhost",user="root",passwd="admin")
c=[Link]()
[Link]('use infomatics')
while True:
pid=input('Enter PID:')
pname=input('Enter Pname:')
price=input('Enter Pprice:')
doe=input('Enter date:')
d='insert into product values("%s","%s",%s,"%s")'%(pid,pname,price,doe)
[Link](d)
[Link]()
ch=input('(Y/N)')
if ch in 'nN':
break
[Link]('select*from product')
for i in c:
print(i)
[Link]()
8.)Parameterised Query-(.format with placeholder{})
import pymysql as a
b=[Link](host="localhost",user="root",passwd="admin")
c=[Link]()
[Link]('use infomatics')
while True:
pid=input('Enter PID:')
pname=input('Enter Pname:')
price=input('Enter Pprice:')
doe=input('Enter date:')
d="insert into product values('{}','{}','{}','{}')".format(pid,pname,price,doe)
[Link](d)
[Link]()
ch=input('(Y/N)')
if ch in 'nN':
break
[Link]('select*from product')
g=[Link]()
print(g)
print("Total no of rows retrieved",[Link])
10.)Parameterised Query-(.format with placeholder{})-[without showing the table]
import pymysql as a
b=[Link](host="localhost",user="root",passwd="admin")
c=[Link]()
[Link]('use infomatics')
while True:
pid=input('Enter PID:')
pname=input('Enter Pname:')
price=input('Enter Pprice:')
doe=input('Enter date:')
d="insert into product values('{}','{}','{}','{}')".format(pid,pname,price,doe)
[Link](d)
[Link]()
ch=input('(Y/N)')
if ch in 'nN':
break
print("Total no of rows inserted",[Link])
[Link]()