Test Index
CBSE Class 12 Computer Science 2025 Paper Set 4
© examsnet.com
Question : 35 of 37
Marks:
+1,
-0
A table, named THEATRE, in CINEMA database, has the following structure :
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
| Field | Type |
|---|---|
| Th_ID | char(5) |
| Name | varchar(15) |
| City | varchar(15) |
| Location | varchar(15) |
| Seats | int |
Solution:
Concept: Steps of Python-MySQL connectivity: import the connector, connect to the CINEMA database, create a cursor, execute the DELETE query, and call
commit() so that the deletion is saved permanently, then close the connection.import mysql.connector as mycondef Delete_Theatre(): con = mycon.connect(host="localhost", user="root", password="Ex2025", database="CINEMA") cur = con.cursor() tid = input("Enter Th_ID of the theatre to delete: ") query = "DELETE FROM THEATRE WHERE Th_ID = '{}'".format(tid) cur.execute(query) con.commit() # makes the delete permanent print(cur.rowcount, "record(s) deleted") con.close()Delete_Theatre()Explanation:• Th_ID is char(5), so its value is put inside quotes in the query.• The query can also be written with a placeholder: cur.execute("DELETE FROM THEATRE WHERE Th_ID = %s", (tid,)).• Without con.commit() the deletion is not saved in the table.© examsnet.com
Go to Question: