Python SQL MCQs: 11 Solved Python-MySQL Questions with Explanations
Trace Python-MySQL connections, cursors, result retrieval, transactions and CRUD through one SCHOOL database example and clear question explanations.
KnowledgeGate Team
Exam prep & CS education

Python-SQL questions mix three layers that learners often collapse into one: the connector, the connection object and the cursor object. A method can look familiar and still belong to the wrong layer. The connector opens the database connection, the connection creates cursors and commits changes, and each cursor executes SQL and fetches results. If Python behaviour itself also needs revision, practise these Python output-based questions.
Build the connection-cursor-query mental model first

The SCHOOL example links the connector, connection, cursor and query. Database SCHOOL has a table Student(rno, name, marks) containing (101, 'Asha', 82), (102, 'Ravi', 91) and (103, 'Neha', 76). The connector creates a connection to SCHOOL. The connection creates cur = conn.cursor(). The cursor then runs:
cur.execute(
"SELECT rno, name FROM Student WHERE marks >= %s ORDER BY rno",
(80,)
)
rows = cur.fetchall()The threshold is 80. Asha has 82 and Ravi has 91, so rows is [(101, 'Asha'), (102, 'Ravi')]. Neha has 76 and does not qualify. The returned-row count for this query is 2. Close the cursor and connection when the work is complete.
Keep ownership clear. The connector module exposes connect(). The returned connection exposes cursor() and commit(). The cursor exposes execute(), fetchall() and rowcount. With Connector/Python's default MySQLCursor, fetchall() returns a list of tuples. PyMySQL's default cursor returns a tuple of tuples, so the driver named in the stem controls the container type.

Connection setup and the database choice: Questions 1-3
Question 1
Which of the following is an example of an open-source RDBMS (Relational Database Management System) software?A. MySQL
B. Amazon RDS
C. Oracle Database
D. Azure SQL DatabaseAnswer: A. MySQL. MySQL Community Edition is the open-source RDBMS intended by this item. Amazon RDS and Azure SQL Database are managed cloud database offerings. Oracle Database is not the open-source choice in this set. Open the solved question.
Question 2
Which method is used to create a connection object between a Python script and a MySQL database assuming that the module pymysql is imported?A. pymysql.open()
B. pymysql.connect()
C. pymysql.link()
D. pymysql.join()Answer: B. pymysql.connect(). A minimal shape is conn = pymysql.connect(host=host, user=user, password=password, database='SCHOOL'). Read the credential variables from environment or secret storage instead of hard-coding them. open, link and join are name-shaped distractors, not connection functions. Open the solved question.
Question 3
The connect() method establishes a Python-MySQL connection. Which option is not a connect() argument?A. user
B. password
C. database
D. tableAnswer: D. table. Use database='SCHOOL' while connecting, then mention Student inside a later SELECT, INSERT, UPDATE or DELETE statement. A connection establishes server, authentication and database context. A table is not the connect() argument tested here. Open the solved question.
Cursor creation and responsibility: Questions 4-5
Question 4
The cursor() method is used in Python-MySQL connectivity applications. Which option identifies the relevant library family?A. sql module
B. pickle module
C. database-connectivity module
D. csv moduleAnswer: C. database-connectivity module. Among the given options, C names the relevant library family. In actual Python code, cursor() is a method of the connection object, so call cur = conn.cursor(). pickle serialises Python objects, while csv handles delimited text. Neither creates a database cursor. Open the solved question.
Question 5
In Python-MySQL connectivity, what is the primary purpose of a Cursor object?A. To store the password for the database connection.
B. To visually point to the data in the MySQL Workbench.
C. To execute SQL queries and fetch results from the database.
D. To act as a backup of the entire database.Answer: C. To execute SQL queries and fetch results from the database. In the SCHOOL example, cur.execute(...) sends the query and cur.fetchall() retrieves its result. A cursor is a programmatic query and result interface, not a mouse pointer, credential store or database backup. Open the solved question.
Fetching rows and counting results: Questions 6-8
Using Connector/Python's default MySQLCursor, run the first query again. Its ordered result is [(101, 'Asha'), (102, 'Ravi')]: the outer list holds all returned rows, and each inner tuple holds one row's selected values. The same shape appears often when practising SQL queries for placement interviews.
Question 6
While working with Connector/Python's default MySQLCursor, what does fetchall() return?A. a list
B. a tuple
C. a tuple of lists
D. a list of tuplesAnswer: D. list of tuples. With Connector/Python's default MySQLCursor, [(101, 'Asha'), (102, 'Ravi')] is a list containing two tuples. Each tuple keeps the rno and name values from one returned row together. PyMySQL's default cursor would return a tuple of tuples instead. Open the solved question.
Question 7
Which datatype is mostly returned by fetchall() in Connector/Python's default MySQLCursor?A. A single list, or an empty list if no rows are available
B. A list of tuples, or an empty list if no rows are available
C. A list of dictionaries, or an empty list if no rows are available
D. A single tuple, or an empty tuple if no rows are availableAnswer: B. A list of tuples, or an empty list if no rows are available. With Connector/Python's default MySQLCursor, change the condition to marks >= 95: 82, 91 and 76 are all below 95, so no sample row qualifies and fetchall() returns []. Open the solved question.
Question 8
In MySQL-Python connectivity, after executing a SELECT query using a cursor object, which attribute or method is used to determine the number of rows fetched or returned by the most recently executed query?A. count()
B. count(*)
C. rowcount
D. rowcount()Answer: C. rowcount. For the ordered SCHOOL query, cur.rowcount == 2 after fetchall() reads both rows. rowcount is an attribute, so it has no parentheses. SQL's COUNT(*) instead asks the database to calculate a count inside a query. Open the solved question.
COMMIT, DML and DDL: Questions 9-10
Begin with the original three rows. Execute INSERT INTO Student VALUES (104, 'Ishaan', 88), then use conn.commit() so the new row is saved when autocommit is off. SELECT only reads rows and needs no commit. ALTER changes the table definition and causes an implicit commit in MySQL.
Question 9
Identify the command from the following options that does not require a COMMIT statement to save changes permanently in Python-MySQL connectivity, as it is auto-committed by MySQL?A. INSERT
B. UPDATE
C. DELETE
D. ALTERAnswer: D. ALTER. INSERT, UPDATE and DELETE change rows and need an explicit commit when autocommit is off. ALTER changes table structure and causes an implicit commit in MySQL. Open the solved question.
Question 10
commit() is required to be used after the execution of certain queries in Python-MySQL connectivity applications. Identify one such MySQL command out of the following options:A. CREATE
B. INSERT
C. SELECT
D. DROPAnswer: B. INSERT. In this example, run cur.execute("INSERT INTO Student VALUES (104, 'Ishaan', 88)"), followed by conn.commit() when autocommit is off. SELECT reads data. CREATE and DROP are DDL distractors in this item. Open the solved question.
CRUD is the four-operation map: Question 11
CRUD names four conceptual database operations. On Student, Create inserts (104, 'Ishaan', 88). Read selects students with marks >= 80. Update changes Ishaan's marks from 88 to 90. Delete removes the row with rno = 104. The matching SQL verbs are INSERT, SELECT, UPDATE and DELETE. CRUD is not the name of a Python connector method.
Question 11
What is CRUD an acronym for in database operations?A. Create, Read, Update, Delete
B. Cache, Read, Update, Delete
C. Copy, Replace, Update, Delete
D. Collect, Read, Use, DiscardAnswer: A. Create, Read, Update, Delete. Each letter maps directly to one of the four operations above. Open the solved question.
A 30-second revision checklist and next step
Establish database access: connector
connect().Create the query interface:
connection.cursor().Run and read results: cursor
execute()andfetchall().Count in these items:
rowcount, without parentheses.Save an
INSERT:connection.commit(). CRUD means Create, Read, Update, Delete.
Avoid three traps: putting a table name into connect(), confusing the connection with the cursor, and treating rowcount as a method. If the layers are still blending together, work through Python Course: Concepts, MCQs & Coding. For broader programming practice, use the Coding & DSA Courses collection.
Now rebuild the first trace from memory with marks >= 85 ORDER BY rno. Before inserting Ishaan, only Ravi's 91 qualifies, so expect [(102, 'Ravi')]. After inserting (104, 'Ishaan', 88) and committing it, Ravi and Ishaan qualify, so expect [(102, 'Ravi'), (104, 'Ishaan')].
Keep learning
SQL ORDER BY and Alias MCQs: 11 Solved Questions with Explanations
Practise 11 SQL MCQs covering aliases, sort direction, multiple sort keys, DISTINCT, explicit null placement and zero-based LIMIT offsets.
Python Character Set, Tokens, Keywords, Identifiers and Literals MCQs: 11 Solved Questions
Solve 11 Python MCQs by applying a clear test for identifiers, keywords, literals, assignment, rebinding, tuple syntax and format rounding.
SELECT, WHERE and DISTINCT MCQs: 12 Solved SQL Questions with Explanations
Test the SQL basics that decide columns, filter rows and remove duplicates. Attempt 12 MCQs, then use each short solution to diagnose the exact rule involved.
Views and PL/SQL Basics MCQs: 12 Solved Questions with Explanations
Test views, materialized views, PL/SQL purity, Pro*C and trigger syntax with 12 solved MCQs. Each explanation separates the right rule from its distractors.





