0% found this document useful (0 votes)
15 views7 pages

Python Exp 6

Uploaded by

BADASS GAMING YT
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)
15 views7 pages

Python Exp 6

Uploaded by

BADASS GAMING YT
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

Experiment : 06

Title : Program to demonstrate CRUD (create, read, update and delete) operations on
database using python.

Program:

Aim : Program To create database


import pymysql
#step1: Established connection with database
mycon=[Link](host='localhost',user='root',passwd='')
print(mycon)
#step2:Create a Cursur(place Where SQL queries are written in the memory area
mycur=[Link]()
#step3:Execute the sql queries
[Link]("create database pythondb")
print('----Database crated----')
#step4: close the connection
[Link]()

Aim : Program to create table


import pymysql
mycon=[Link](host='localhost',user='root',password='',
database='pythondb')
mycur=[Link]()
[Link]('create table student(rollno int primary key,name
varchar(20),marks float,dob date)')
print('table created...')
[Link]()

Aim : Program To insert values in the table


import pymysql
mycon=[Link](host='localhost',user='root',password='',
database='pythondb')
mycur=[Link]()
[Link]("insert into student
values(101,'Prashant',90,'1991-12-23')")
[Link]("insert into student
values(102,'Shivendra',100,'1984-10-03')")
[Link]("insert into student
values(103,'Ayush',45,'1992-09-10')")
[Link]("insert into student
values(104,'Nilesh',60,'1990-01-15')")
[Link]("insert into student
values(105,'Anand',80,'1991-05-19')")
print('---Record inserted__')
[Link]()
[Link]()

Aim : Program to update values in the table


import pymysql
mycon=[Link](host='localhost',user='root',password='',
database='pythondb')
mycur=[Link]()
[Link]("update student set marks=100 where rollno=101")
print('Record updated.....')
[Link]()
[Link]()
Aim : Program to delete values from the table
import pymysql
mycon=[Link](host='localhost',user='root',password='',
database='pythondb')
mycur=[Link]()
[Link]("delete from student where rollno=105")
print('Record delete.....')
[Link]()
[Link]()
Aim : Program to take user input .
import pymysql
mycon=[Link](host='localhost',user='root',password='',
database='pythondb')
mycur=[Link]()
vrollno=input('Enter the rollno')
vname=input('Enter the name')
vmarks=input('Enter the marks')
vdob=input('Enter the date of birth')
[Link]("insert into studentvalues ('"+vrollno+"'
,'"+vname+"' ,'"+vmarks+"
','"+vdob+"' )")
print('Record inserted....')
[Link]()
[Link]()
Final Output:
Conclusion: In this experiment we learned to demonstrate CRUD (create, read, update and
delete) operations on database using python.

You might also like