Standard difficulty · 20 questions · 40 marks · Time: 40 minutes
Show your working for Sections B and C. Answers are on the last page — try every question first!
Interface Python with MySQL · AW-12CS-PSQ-2026-V1 · For parents — fold back or tear off before handing the sheet to your child.
| Q | Answer | Working |
|---|---|---|
| 1 | (d) connect() | — |
| 2 | (a) 3 3 | fetchone() gives the next row as a tuple; fetchall() gives all remaining rows as a list of tuples |
| 3 | (c) 2 | rows where Marks < 66 |
| 4 | (a) SELECT * FROM STUDENT WHERE City = 'Shimla' AND Marks > 70 | format() puts its arguments into the {} places in order |
| 5 | (c) gives the number of rows fetched or changed | — |
| 6 | (d) 4 | rows where Sec IN ('A', 'C') |
| 7 | (c) cur.execute("INSERT INTO STUDENT (RollNo, Name, Marks) VALUES (%s, %s, %s)", (40, 'Kabir', 47)) | execute() takes the query and a tuple of values for the %s places |
| 8 | (b) it is left unchanged | without commit() the change is not saved |
| 9 | It is the object that sends SQL statements to the database with execute() and holds the result rows to be fetched. | — |
| 10 | 2 2 | fetchone() returns a tuple; fetchall() a list of tuples |
| 11 | (a) 5; (b) 3 | DELETE removes the matching rows |
| 12 | SELECT Name FROM STUDENT WHERE Marks >= 50 AND City = 'Indore' | format() fills the {} places in order |
| 13 | d, b, a, c, e, f | Import the connector module → Connect to the database with connect() → Create a cursor with cursor() → Run the query with execute() → Fetch the rows with fetchall() or fetchone() → Close the connection with close() |
| 14 | 6 | rows where Sec <> 'A' |
| 15 | 2 | 5 rows in the result; 3 already fetched |
| 16 | ('Dev', 88) | the first row of the sorted result, as a tuple |
| 17 | 1. import mysql.connector as m; 2. con = m.connect(host='localhost', user='root', password='…', database='school'); 3. cur = con.cursor(); 4. cur.execute('SELECT * FROM STUDENT'); 5. rows = cur.fetchall(); for r in rows: print(r); 6. con.close(). | — |
| 18 | (a) 6 6; (b) connect() opens the connection to the database, cursor() makes the object that runs queries, execute() runs the SQL; (c) it frees the connection on the server. | fetchone()/fetchall() read the result |
| 19 | (a) 1, 7; (b) changes made by UPDATE or DELETE are not saved in the database until they are committed. | UPDATE keeps every row |
| 20 | import mysql.connector as m; con = m.connect(host='localhost', user='root', password='…', database='school'); cur = con.cursor(); c = input('City: '); k = int(input('Marks: ')); cur.execute("SELECT Name, Marks FROM STUDENT WHERE City = %s AND Marks > %s", (c, k)); for row in cur.fetchall(): print(row[0], row[1]); con.close(). For Delhi and 55 it prints: nothing. | connect → cursor → execute with a tuple → fetchall → close |