0% found this document useful (0 votes)
3 views

Python_SQL_Connectivity

Uploaded by

renu.mishra340
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python_SQL_Connectivity

Uploaded by

renu.mishra340
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

print("OK")

import mysql.connector

cnx = mysql.connector.connect(user='root', password='jsbc@123',

host='localhost',

database='school')

'''

#CODE TO DELETE THE RECORD

mycursor = cnx.cursor()

#statement ="DELETE from std WHERE r = 4 "

mycursor.execute("CREATE TABLE Mrk (roll int, nm VARCHAR(20), tot_mrk int, per float)")

print("Table Created")

'''

'''

#CODE TO DELETE THE RECORD

mycursor = cnx.cursor()

#statement ="DELETE from std WHERE r = 4 "

mycursor.execute("DELETE from std WHERE r = 3 ")

cnx.commit()

print("Record Delete")

'''
'''

#CODE TO MODIFY THE RECORD

mycursor = cnx.cursor()

statement ="UPDATE std SET nm = 'aaaaaaa' WHERE r = 1 "

mycursor.execute(statement)

cnx.commit()

print("Record modified")

'''

'''

#CODE TO INSERT A NEW RECORD

rn=int(input("Enter a roll number"))

n=input("Enter a name")

sql = "INSERT INTO std (r, nm) VALUES (%s, %s)"

val = (rn,n)

mycursor = cnx.cursor()

mycursor.execute(sql, val)

cnx.commit()
print(mycursor.rowcount, "record inserted.")

'''

'''

#CODE TO RETRIEVE AND DISPLAY THE RECORDS

mycursor = cnx.cursor()

mycursor.execute("SELECT * FROM std")

myresult = mycursor.fetchall()

print("Roll",'\t\t','Name')

for x in myresult:

for b in x:

print(b,end='\t\t ')

print()

'''

You might also like