1.

Write a Python script to create a table called ITEM with following specification?                 SUPPLIERSuppnoNameCityIcodeSuppQtyS001PrasadDelhi1008100S002AnuBangalore1010200S003ShahidBangalore1008175S004AkilaHydrabad1005195S005GirishHydrabad100325S006ShylajaChennai1008180S007LavanyaChennai10053251. Display Name, City and Itemname of suppliers who do not reside in Delhi.2. Increment the SuppQty of Akila by 40

Answer»

1. import sqlite3

connection = sqlite3.connect(“ABC.db”)

cursor = connection,cursor( ) 

cursor.execute(“SELECT Supplier.Name, Supplier.city,

Item.ItemName FROM Supplier, Item

where Supplier.Icode = Item.Icode AND Supplier.city NOT IN ‘Delhi'”)

co=[i[0] for i in cursor.description]

print(co)

result = cursor. fetchall( )

for r in result:

print(r)

Output:

[‘Name’ , ‘City’ , ‘ItemName’]

[‘Anu’ , ‘Bangalore’ , ‘Mouse’]

[‘Shahid’ , ‘Bangalore’ , ‘Monitor’]

[‘Akila’ , ‘Hydrabad’ , ‘Printer’]

[‘Girish’ , ‘Hydrabad’ , ‘Scanner’]

[‘Shylaja’ , ‘Chennai’ , ‘Monitor’]

[‘Lavanya’ , ‘Mumbai’ , ‘Printer’]

2. Increment the suppQty of Akila by 40 import sqlite3 connection = sqlite3.connect(“ABC.db”) 

cursor = connection.cursor( ) 

cursor.execute(“UPDATE Supplier SET SuppQty = 

SuppQty + 40 where Name = ‘Akila'”) 

cursor.commit( )

result = cursor. fetchall( )

print(result)

connection.close( )

Output:

(S004, ‘Akila’ , ‘Hydrabad’ , 1005, 235)



Discussion

No Comment Found