Humanities/Arts Exam  >  Humanities/Arts Tests  >  Computer Science for Class 12  >  Test: Interface Python with SQL Database- 1 - Humanities/Arts MCQ

Test: Interface Python with SQL Database- 1 - Humanities/Arts MCQ


Test Description

10 Questions MCQ Test Computer Science for Class 12 - Test: Interface Python with SQL Database- 1

Test: Interface Python with SQL Database- 1 for Humanities/Arts 2024 is part of Computer Science for Class 12 preparation. The Test: Interface Python with SQL Database- 1 questions and answers have been prepared according to the Humanities/Arts exam syllabus.The Test: Interface Python with SQL Database- 1 MCQs are made for Humanities/Arts 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Interface Python with SQL Database- 1 below.
Solutions of Test: Interface Python with SQL Database- 1 questions in English are available as part of our Computer Science for Class 12 for Humanities/Arts & Test: Interface Python with SQL Database- 1 solutions in Hindi for Computer Science for Class 12 course. Download more important topics, notes, lectures and mock test series for Humanities/Arts Exam by signing up for free. Attempt Test: Interface Python with SQL Database- 1 | 10 questions in 15 minutes | Mock test for Humanities/Arts preparation | Free important questions MCQ to study Computer Science for Class 12 for Humanities/Arts Exam | Download free PDF with solutions
Test: Interface Python with SQL Database- 1 - Question 1

Mandatory arguments required to connect any database from Python

Detailed Solution for Test: Interface Python with SQL Database- 1 - Question 1

To create a connection between the MySQL database and python application, the connect( ) function is used. The functions requires 4 parameters:

  • Hostname
  • Username
  • Password 
  • Database name

Checking the options
(A) Username, Password, Hostname, Database  Name, Port. - Port is not a parameter of the function connect( ).
(B) Username, Password, Hostname. - The parameter database name is missing.  
(C) Username, Password, Hostname, Database  Name. - All 4 parameters of the function connect( ) are present. 
(D) Username, Password, Hostname, Port. - Port is not a valid parameter and the parameter database name is missing.  
From the options given above, only option C has all the 4 parameters of function connect( ).
So, the correct answer is (C)

Test: Interface Python with SQL Database- 1 - Question 2

Which method of cursor class is used to fetch limited rows from the table?

Detailed Solution for Test: Interface Python with SQL Database- 1 - Question 2

Checking the options
(A) cursor.fetchsize(SIZE) - It is not a method of cursor class.
(B) cursor.fetchmany(SIZE) - It returns the number of rows specified by the size argument.
(C) cursor.fetchall(SIZE) - It returns all the rows of a query result.   
(D) cursor.fetchonly(SIZE) - It is not a method of cursor class.
From the options given above, the function cursor.fetchmany(SIZE) is used to fetch limited rows from the table.
So, the correct answer is (B)

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Interface Python with SQL Database- 1 - Question 3

Which method of cursor class is used to insert or update multiple rows using a single query?

Detailed Solution for Test: Interface Python with SQL Database- 1 - Question 3

Checking the options:
(A) cursor.executeall(query, rows) - It is not a method of cursor class.  
(B) cursor.execute(query, rows)  - It executes the given SQL statement.
(C) cursor.executemultiple (query, rows) - It is not a method of cursor class.  
(D) cursor.executemany(query, rows) - It executes more than one SQL statement together.
From the options given above, the function cursor.executemany(query, rows) is used to insert or update multiple rows using a single query
So, the correct answer is (D)

Test: Interface Python with SQL Database- 1 - Question 4

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?

Detailed Solution for Test: Interface Python with SQL Database- 1 - Question 4

Checking the options
(A) cursor.rowcount - It returns the number of rows affected by DML statements.  
(B) cursor.getaffectedcount  - It is not a method of cursor class.
(C) cursor.rowscount - It is not a method of cursor class.
(D) cursor.rcount - It is not a method of cursor class.
From the options given above, the function cursor.rowcount is used to get the  number of rows affected after any of the insert/update/delete database operations executed from Python.
So, the correct answer is (A)

Test: Interface Python with SQL Database- 1 - Question 5

_______ is the set of records that are retrieved after execution of SQL query over an established database connection.

Detailed Solution for Test: Interface Python with SQL Database- 1 - Question 5

Checking the options
(A) sqlresult - It is not a valid term related to SQL.  
(B) resultset - It refers to the logical set of records that are fetched from the database when executing an SQL query.
(C) table - It refers to a database object that contains all the data in the table in the form of rows and columns.
(D) tuple - It refers to a single row of a table in an SQL database.
From the options given above, resultset refers to  the set of records that are retrieved  after execution of SQL query over an established  database connection. 
So, the correct answer is (B)

Test: Interface Python with SQL Database- 1 - Question 6

Which of the following is invalid method for fetching the records from database within Python?

Detailed Solution for Test: Interface Python with SQL Database- 1 - Question 6

There are 3 methods used for fetching the records from a database within python.

Checking the options
(A) fetchone( ) - It is a valid method for fetching records from a database within python.
(B) fetchmany( ) - It is a valid method for fetching records from a database within python.  
(C) fetchall( ) - It is a valid method for fetching records from a database within python.
(D) fetchmulti( ) - It is not a valid method for fetching records from a database within python.

Test: Interface Python with SQL Database- 1 - Question 7

Which of the following method reflects the changes made in database permanently?

Detailed Solution for Test: Interface Python with SQL Database- 1 - Question 7

The commit( ) method in python is used to confirm the changes made by the user to a database.
Checking the options
(A) <connection>.done( ) - It is not a valid method used to reflect changes made in the database permanently.  
(B) <connection>.final( ) -  It is not a valid method used to reflect changes made in the database permanently.    
(C) <connection>.reflect( ) -  It is not a valid method used to reflect changes made in the database permanently.    
(D) <connection>.commit( ) -  This method used to reflect changes made in the database permanently .  
So, the correct answer is (D)

Test: Interface Python with SQL Database- 1 - Question 8

The special control structure that facilitates row by row processing of records in resultset.

Detailed Solution for Test: Interface Python with SQL Database- 1 - Question 8

Checking the options
(A) Tuple - It refers to a single row of a table in an SQL database.
(B) database cursor - It is a database object that retrieves data from the result set one row at a time.  
(C) connection - It refers to creating a link between the MySQL database and the python application.  
(D) None of these
From the options given above, database cursor refers to the special control structure that facilitates row by  row processing of records in resultset. 
So, the correct answer is (B)

Test: Interface Python with SQL Database- 1 - Question 9

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()

Q. What of the following statement is connecting database server?

Detailed Solution for Test: Interface Python with SQL Database- 1 - Question 9

(A) importMySQLdb - Imports the required python module
(B) MySQLdb.connect - Connects the MySQL server to the python application   
(C) db.cursor - Creates the cursor object which is used for executing the queries
(D) None of these 
From the options given above, MySQLdb.connect creates a connection to the MySQL server.
So, the correct answer is (B)

Test: Interface Python with SQL Database- 1 - Question 10

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()

Q. The role of the statement ‘cursor=db.cursor’ is:

Detailed Solution for Test: Interface Python with SQL Database- 1 - Question 10

The statement ‘cursor=db.cursor’ is used to create an object ‘db’ of the cursor class.
Checking the options
(A) Create an instance of a cursor - It is a role of the given statement
(B) Moves cursor row wise -  It is not a role of the given statement
(C) Connects cursor to database -  It is not a role of the given statement   
(D) Prepares cursor to move -  It is not a role of the given statement
So, the correct answer is (A)

1 videos|26 docs|18 tests
Information about Test: Interface Python with SQL Database- 1 Page
In this test you can find the Exam questions for Test: Interface Python with SQL Database- 1 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Interface Python with SQL Database- 1, EduRev gives you an ample number of Online tests for practice

Top Courses for Humanities/Arts

1 videos|26 docs|18 tests
Download as PDF

Top Courses for Humanities/Arts