Consider the table Product with following structure.
P_ID, ProductName, Manufacturer, Price.
Write Python code to increase the price of all products by 50.
Answer:
import mysql.connector
mydb=mysql.connector.connect('localhost','root','root','sales')
cursor=mydb.cursor()
sql="update product set price=price+50;"
try:
cursor.execute(sql)
mydb.commit()
except:
mydb.rollback()
cursor.close()
mydb.close