CBSE · 083Class XII · 2022Section A2 marks

Question 04

7 June 2022 · Computer Science (083)

Consider the following SQL table MEMBER in a SQL Database CLUB :

Table : MEMBER

M_IDNAMEACTIVITY
M1001AminaGYM
M1002PratikGYM
M1003SimonSWIMMING
M1004RakeshGYM
M1005AvneetSWIMMING

Assume that the required library for establishing the connection between Python and MySQL is already imported. Also assume that DB is the database connection object for the database CLUB.

Predict the output of the following code :

python
MYCUR = DB.cursor()
MYCUR.execute("USE CLUB")
MYCUR.execute("SELECT * FROM MEMBER WHERE ACTIVITY='GYM' ")
R = MYCUR.fetchone()
for i in range(2):
    R = MYCUR.fetchone()
    print(R[0], R[1], sep="#")

Answer

text
M1002#Pratik
M1004#Rakesh

Explanation

The SELECT returns the 3 GYM members in order: Amina, Pratik, Rakesh. The first fetchone() consumes Amina (but doesn't print). The loop then fetches and prints the next two rows — Pratik and Rakesh — joining M_ID and NAME with '#'.