CBSE · 083Class XII · 2025Section D4 marks
Question 35
4 March 2025 · Computer Science (083)
A table, named THEATRE, in CINEMA database, has the following structure:
| Fields | Type |
|---|---|
| Th_ID | char(5) |
| Name | varchar(15) |
| City | varchar(15) |
| Location | varchar(15) |
| Seats | int |
Write a function Delete_Theatre(), to input the value of Th_ID from the user and permanently delete the corresponding record from the table.
Assume the following for Python-Database connectivity: Host : localhost, User : root, Password : Ex2025
Answer
python
import pymysql as pm
def Delete_Theatre():
mydb=pm.connect(host='localhost',user='root',password='Ex2025',database='CINEMA')
MyCursor = mydb.cursor()
TID = input("Theatre ID:")
Query = "DELETE FROM Theatre WHERE Th_ID=%s"
Data=(TID,)
MyCursor.execute(Query, Data)
mydb.commit()
mydb.close()Explanation
Connects to DB, accepts ID, executes DELETE query, commits changes.