Check sibling questions
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()

 

Are ads bothering you?

Davneet Singh's photo - Teacher, Engineer, Marketer

Made by

Davneet Singh

Davneet Singh is a graduate from Indian Institute of Technology, Kanpur. He has been teaching from the past 12 years. He provides courses for Maths and Science at Teachoo.