Computer Science - Class 12
Chapter 15 - Interface of Python with SQL Database

Consider the following table OrderDetails of database sales

ORDNUMB PARTNUMB NUMBORD QUOTPRIP
12494 CB03 4 175
12495 CX11 2 57.95
12498 AZ52 2 22.95
12500 BT04 1 402.99

Write Python code to increase NUMBORD by 5 if QUOTPRIC is less than 100 or NUMBORD is greater than 3.

 

Answer:

import mysql.connector.connect

 

db=mysql.connector.connect('localhost','root','root','sales')

cursor=db.cursor()

sql="UPDATE OrderDetails set NUMBORD=NUMBORD+5 where QUOTPRIC<100 OR NUMBORD>3"

try:

cursor.execute(sql)

db.commit()

except:

db.rollback()

db.close()

 

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo