MCQ Question for Class 12 Computer Science Chapter 5 Interface Python with SQL

MCQs Class 12

Check the below NCERT MCQ Class 12 Computer Science Chapter 5 Interface Python with SQL with Answers available with PDF free download. MCQ Questions for Class 12 Computer Science with Answers were prepared based on the latest syllabus and examination pattern issued by CBSE, NCERT and KVS. Our teachers have provided below Interface Python with SQL Class 12 Computer Science MCQs Questions with answers which will help students to revise and get more marks in exams

Interface Python with SQL Class 12 Computer Science MCQ Questions with Answers

Refer below for MCQ Class 12 Computer Science Chapter 5 Interface Python with SQL with solutions. Solve questions and compare with the answers provided below

Question. ……… operation is required when you want to create your records into a database’s table.
(a) Update
(b) Delete
(c) Read
(d) Insert 

Answer

D

Question. What is default value of host?
(a) host
(b) localhost
(c) global host
(d) None of these

Answer

B

Question. User can write Python script using
(a) mysql.connector library
(b) sql.connect library
(c) mysql.connect library
(d) None of the above

Answer

A

Question. Which command is used to display the name of existing databases?
(a) display databases;
(b) result databases;
(c) show databases;
(d) output databases;

Answer

C

Question. Which method returns the next row from the result set as tuple?
(a) fetchone ( )
(b) fetchmany ( )
(c) fetchall ( )
(d) rowcount

Answer

A

Question. Which of the following method is used to create a connection between the MySQL database and Python?
(a) connector ( )
(b) connect ( )
(c) con ( )
(d) cont ( ) 

Answer

B

Question. Which method is used to get the row-id of the last modified row?
(A) cursor.getrowid()
(B) cursor.endrowid()
(C) cursor.lastrowid()
(D) cursor.exitrowid()
Ans. Option (C) is correct.

Answer

C

Question. Which method of cursor class is used to fetch limited rows from the table?
(A) cursor.fetchsize(SIZE)
(B) cursor.fetchmany(SIZE)
(C) cursor.fetchall(SIZE)
(D) cursor.fetchonly(SIZE)
Ans. Option (B) is correct.

Answer

B

Question. Which method of cursor class is used to insert or update multiple rows using a single query?
(A) cursor.executeall(query, rows)
(B) cursor.execute(query, rows)
(C) cursor.executemultiple (query, rows)
(D) cursor.executemany(query, rows)
Ans. Option (D) is correct.

Answer

D

Question. Which method is used to retrieve the executed database function or stored procedure result in Python?
(A) cursor.stored_results()
(B) cursor.get_results()
(C) cursor.fetch_results()
(D) cursor.show_results()
Ans. Option (A) is correct.

Answer

A

Question. Mandatory arguments required to connect any database from Python
(A) Username, Password, Hostname, Database Name, Port.
(B) Username, Password, Hostname.
(C) Username, Password, Hostname, Database Name.
(D) Username, Password, Hostname, Port.
Ans. Option (C) is correct.

Answer

C

Question. Which method of cursor class is used to execute database function or stored procedure in Python
(A) cursor.callprocedure(‘procedureName’, [parameters,])
(B) cursor.callproc(‘procedureName’, [parameters,])
(C) cursor.callfunc(‘procedureName’, [parameters,])
(D) cursor.callfunction(‘procedureName’, [parameters,])
Ans. Option (B) is correct.

Answer

B

Question. _________ is the set of records that are retrieved after execution of SQL query over an established database connection.
(A) sqlresult
(B) resultset
(C) table
(D) tuple
Ans. Option (B) is correct.

Answer

B

Question. Which of the following is invalid method for fetching the records from database within Python?
(A) fetchone()
(B) fetchmany()
(C) fetchall()
(D) fetchmulti()
Ans. Option (D) is correct.

Answer

D

Question. Exception raised when the relational integrity of the database is affected in Python
(A) IntegrityFailError
(B) IntegrityFailure
(C) IntegrityViolationError
(D) IntegrityError
Ans. Option (D) is correct.

Answer

D

Question. Which method of cursor class is used to get the number of rows affected after any of the insert/ update/delete database operation executed from Python?
(A) cursor.rowcount
(B) cursor.getaffectedcount
(C) cursor.rowscount
(D) cursor.rcount
Ans. Option (A) is correct.

Answer

A

Question. Which of the following method reflects the changes made in database permanently?
(A) <connection>.done()
(B) <connection>.final
(C) <connection>.reflect()
(D) <connection>.commit()

Answer

D

Question. Which of the following database servers is/are supported by Python DB-API?
(A) MySQL
(B) Interbase
(C) Oracle
(D) All of these

Answer

D

Question. ______ method is used to retrieve the original data that was changed through the commit() method.
(A) execute()
(B) rollback()
(C) update ()
(D) close()

Answer

B

Question. The special control structure that facilitates row by row processing of records in resultset.
(A) Tuple
(B) database cursor
(C) connection
(D) None of these

Answer

B

Question. To get all the records from the result set, you may use _____.
(A) cursor.fetchmany()
(B) cursor.fetchall()
(C) select * from <table name>
(D) cursor.execute ()

Answer

B

Assertion and Reason Based MCQs

Directions : In the following questions, A statement of Assertion (A) is followed by a statement of
Reason (R). Mark the correct choice as. 
(A) Both A and R are true and R is the correct explanation for A.
(B) Both A and R are true and R is not correct explanation for A.
(C) A is true but R is false.
(D) A is false but R is true.

Question. Assertion (A): A cursor is a Python object that enables you to work with the database.
Reason (R): To get a cursor you need to call the cursor method on the database object.

Answer

A

Question. Assertion (A): rowcount() function returns number of rows.
Reason (R): The number of rows from fetch() methods.

Answer

A

Question. Assertion (A): c. fetchone () returns the next row of the query result as a sequence.
Reason (R): c.fetchone () raises an exception if there is no result set.

Answer

A

Question. Assertion (A): connect () function is required to be given in program.
Reason (R): cursor() instantiates objects that can execute operations such as SQL statements .

Answer

C

Question. Assertion (A): fetchall() method returns the records one by one.
Reason (R): fetchone() method retrieves one record from the result set.

Answer

D

Question. Assertion (A): Database connection is closed at the end of processing.
Reason (R) : cursor.close() is given to close the connection.

Answer

C

Question. Assertion (A): The result stored in resultset is extracted using fetch methods.
Reason (R): rowcount() is a property of cursor that returns number of rows.

Answer

B

Question. Assertion (A): n number of rows can be retrieved from the result set.
Reason (R): Fetchmany () method returns n number of records from the resultset.

Answer

A

Question. Assertion (A): SQL query is executed using parameterized execute statement.
Reason (R): The retrieved records are stored as result set

Answer

A

Question. Assertion (A): The commit() function is required to be run at the end of executing queries.
Reason (R) : The changes are reflected in the database.

Answer

A

Question. Assertion (A): A cursor is a control structure that access records.
Reason (R): You can check for connection with using is connected().

Answer

B

Question. Assertion (A): MySQLdb is an interface for connecting to a MySQL database servers from Python.
Reason (R): exit () method is used to close the connection to the database.

Answer

C

Question. Assertion (A): Python Database Connectivity is transfer of data between python programs and MySQL.
Reason (R): Python MySQL Database Connectivity needs to install MySQL connector.

Answer

A

Case Based MCQs :

Consider the table Faculty in which Riya wants to add two rows. For this, she wrote a program in which some code is missing. Help her to complete the following code.

MCQ Question for Class 12 Computer Science Chapter 5 Interface Python with SQL

Question. Identify the correct option to fill the blank as marked statement?
(a) INTO
(b) IN
(c) TO
(d) DATA

Answer

A

Question. Choose the correct option to fill the blank as marked Statement4.
(a) com
(b) committment
(c) commit
(d) None of these

Answer

C

Question. Choose the correct option to fill the blank as marked Statement5.
(a) con.close()
(b) my.close ()
(c) y.close ()
(d) mycon.close ()

Answer

D

Question. Identify the correct option to fill the blank as marked Statement3.
(a) val
(b) value
(c) data
(d) d

Answer

A

Question. Choose the correct option to fill the blank as marked Statement1.
(a) connect
(b) connector
(c) con
(d) mycon

Answer

B

Case-based MCQs

Attempt any 4 sub-parts from each question. Each subpart carries 1 mark.
I. Consider the following code:
importMySQLdb
d b = M y S Q L d b . c o n n e c t ( ‘ l o c a l h o s t ’ ,
‘LIBMAN’,‘Admin@pwd’,‘library’)
cursor=db.cursor(prepared=TRUE)
sql = “””Insert into table(‘MemId’,
‘MemName’,‘MemAdd’,)values(‘%s’,‘%s’,‘%s’, )”””
insert_value=[(‘1021’, ‘Ronit’, ’12, Block A, Kaveri
Vihar’ ),
      (‘1022’, ‘Smriti’, ‘12/9 Indira Puram’)]
try:
      cursor.executemany(sql,insert_value)
      print(cursor.rowcount,“Recordsinserted”)
      db.commit()
except:
db.rollback()
      cursor.close()
      db.close()

Question. The role of the statement ‘cursor=db.cursor’ is:
(A) Create an instance of a cursor
(B) Moves cursor row wise
(C) Connects cursor to database
(D) Prepares cursor to move

Answer

A

Question. What of the following statement is connecting database server?
(A) importMySQLdb
(B) MySQLdb.connect
(C) db.cursor
(D) None of these

Answer

B

Question. What will be the output of following statement in the given code?
print(cursor.rowcount,“Recordsinserted”)

(A) 0
(B) 1
(C) 2
(D) 3

Answer

C

Question. Which of the following statement will add the record in the table?
(A) Insert Into
(B) Insert Value
(C) cursor.executemany(sql,insert_value)
(D) None of these

Answer

C

Question. What will be the result of ‘cursor.close()’ ?
(A) Close the cursor
(B) Reset all results
(C) Deletes all references to the connection
(D) All of these

Answer

D

II. Consider the following code:
importMySQLdb
db=MySQLdb.connect(‘localhost’,‘LibMan’,‘isspw
d’,‘Library’)
cursor=db.cursor()
sql=”UPDATE BOOK set Status =‘ISSUE’
whereBookId=’%s’”/(“1021”)
try:
     db.execute(sql)
     db.commit()
except:
     db.rollback()
     db.close()

Question. What will be the result of the above code?
(A) A new record is added
(B) A record with book id ‘1021’ is updated
(C) A record with status ‘Issue’ is updated
(D) All of these

Answer

B

Question. What is “Library” in the statement MySQLdb.connect(‘localhost’,‘LibMan’,‘isspwd’,‘Library’)
(A) User
(B) Password
(C) Table
(D) Database

Answer

D

Question. Which of the following method closes the database connection?
(A) db.commit()
(B) db.rollback()
(C) db.close()
(D) None of these

Answer

C

Question. What is the use of try in above code?
(A) Handles the errors
(B) Try the logic of code
(C) test a block of code for errors
(D) executes the block

Answer

C

Question. What is the function of db.rollbback() in the code?
(A) Returns the database to some previous state
(B) Returns cursor to the previous row
(C) Review the records updated
(D) All of these

Answer

A

III. Consider the following table STUDENT :

MCQ Question for Class 12 Computer Science Chapter 5 Interface Python with SQL

Question. The following sql command has been given:
Sql = “UPDATE student SET result = ‘Passed’
WHERE course = ‘BCom’ ”
The result of which of the following STUID will be changed to “Passed”?
(A) 1101
(B) 1101, 1104
(C) 1101, 1105
(D) 1101, 1104, 1105

Answer

C

Question. What will be the query statement to insert a new record with Student id = 1107, name = Sumit Saxena, Course = BBA and result = passed
(A) sql = “INSERT INTO student (stuid, name, course, result) VALUES (‘1107’, ‘Sumit Saxena’, ‘BBA’, ‘Passed’)”
(B) sql = “INSERT INTO student VALUES (‘1107’, ‘Sumit Saxena’, ‘BBA’, ‘Passed’)”
(C) Both (a) and (b)
(D) None of these

Answer

C

Question. Consider the following code :
sql = ”’SELECT * from STUDENT”’
cursor.execute(sql)
result = cursor.fetchone();
print(result)
What will be the output of the above code in reference to the STUDENT table?
(A) 1101, Anubhav Singh,    BCom,   Awaited
(B) 1106, Sanchit Kumar,     BCom,   Passed
(C) 1103, Kartikey Rana,      BSc,      Passed
(D) Both (A) and (B)

Answer

A

Question. Consider the following code :
cursor=db.cursor()
query = “DELETE FROM student WHERE course
= ‘BCom’ AND result = ‘Awaited’ “
cursor.execute(query)
del_rows= cursor.rowcount
print(del_rows)
What will be the output of the above code?

(A) 1
(B) 2
(C) 3
(D) 4

Answer

B

Question. Consider the following code :
result = cursor.fetchmany(2); print(result)
What will be the result if it is executed after the code given in (iii)?
(A) 1101, Anubhav Singh, BCom, Awaited 1102, Riya Sharma, BSc, Passed
(B) 1102, Riya Sharma, BSc, Passed 1103, Kartikey Rana, BSc, Passed
(C) 1103, Kartikey Rana, BSc, Passed 1104, Archana Kapoor, BBA, Awaited
(D) None of these

Answer

B