0% found this document useful (0 votes)
9 views2 pages

Some SQL Programs

Uploaded by

anandaniriyansh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Some SQL Programs

Uploaded by

anandaniriyansh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#Program to Fetch all the records from the given table in SQL

import mysql.connector as ms

con=ms.connect(host='localhost',user='root',passwd='Nothing$20',database='employees')

if con.is_connected()==False:

print('Error')

cur=con.cursor()

cur.execute('select * from emp')

data=cur.fetchall()

for row in data:

print(row)

#Program to Delete and display the records from the given table in SQL

import mysql.connector as ms

con=ms.connect(host='localhost',user='root',passwd='Nothing$20',database='student')

if con.is_connected()==False:

print('Error')

st=("delete from record where Rollno=106")

cursor=con.cursor()

cursor.execute(st)

con.commit()

cursor.execute('select * from record')

data=cursor.fetchall()

for row in data:

print(row)

#Program to Insert a record and display from the given table in SQL

import mysql.connector as ms

con=ms.connect(host='localhost',user='root',passwd='Nothing$20',database='employees')

if con.is_connected()==False:

print('Error')

st=("insert into emp values(14,'Mahak',5000)")


cursor=con.cursor()

cursor.execute(st)

con.commit()

cursor.execute('select * from emp')

data=cursor.fetchall()

for row in data:

print(row)

#Program to Update a record and display from the given table in SQL

import mysql.connector as ms

con=ms.connect(host='localhost',user='root',passwd='Nothing$20',database='student')

if con.is_connected()==False:

print('Error')

st=("update record set Rollno=106 where Rollno=105")

cursor=con.cursor()

cursor.execute(st)

con.commit()

cursor.execute('select * from record')

data=cursor.fetchall()

for row in data:

print(row)

You might also like