Q. Write a Python database connectivity script that deletes records from category table of database items that have name = 'Stockable'


Answer =

import mysql.connector as ctor
dbcon = ctor.connect (host = "localhost", user = "learner", passwd = "fast", database = "items")
cursor = dbcon.cursor()

sql1 = "DELETE FROM category WHERE name = '%s' "
data1 = ('Stockable',)
cursor.execute(sql1, data1)
dbcon.commit()
print("Rows affected: ", cursor.rowcount)
dbcon.close()

1 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post