Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

SQL Python Connectivity #1

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

Name the method which is used for displaying only one resultset.

a)

fetchmany( )

b)

fetch(1)

c)

fetchall( )

d)

fetchone( )

2.

Identify the Python statement that creates an SQL table out of the following options:

a)

mycursor.execute('CREATE TABLE customers (name VARCHAR(25), 'address' VARCHAR(55))')

b)

mycursor.execute("CREATE TABLE customers (name VARCHAR(25), address VARCHAR(55))")

c)

mycursor.execute("CREATE TABLE customers (name VARCHAR(25), address VARCHAR(55));")

d)

mycursor.execute("CREATE TABLE customers (name VARCHAR(25), address (VARCHAR55))")

3.

Assuming mycur to be a cursor object, which Python function is required to ensure that the inserted record has been added to the mentioned table?

a)

set autocommit()

b)

mycur.commit(1)

c)

mycur.commit()

4.

To close a connection (CON) we must use:

a)

CON.close( )

b)

con.close( )

c)

CON.end( )

d)

close(CON)

5.

Which command is used for counting the number of rows in a database?

a)

countrow

b)

rowcount

c)

count

d)

row_count

6.

To retreive all the rows from the result set, which method is used?

a)

fetchmany

b)

fetch(1)

c)

fetchall( )

d)

fetchone( )

7.

What is the specific purpose of a cursor with respect to SQL and Python connectivity?

a)

It is used to execute SQL statements

b)

It is used to connect SQL table with Python code

c)

It enables the Python programmer to traverse through the records of an associated SQL table

d)

It is used to open an existing database

8.

Which of the following needs to be used to replace the values provided by the user through Python Code and transfer them into the SQL tables?

a)

{s}

b)

(s)

c)

[s]

d)

%s

9.

Consider a case in which the total number of records in an SQL table is 20, and currently the record point is at the beginning of the 7th record. How many records will be fetched from the table if fetchall( ) is used?

a)

13

b)

14

c)

20

d)

7

10.

Consider a case in which the total number of records in an SQL table is 20, and currently the record point is at the beginning of the 7th record. How many records will be fetched from the table if fetchmany(5) is used?

a)

11

b)

7

c)

5

d)

6

11.

Consider the following Python code:

mycur = mycon.cursor()

x=mycur.execute("select * from student where class='XI' and marks>=75")

Assuming that multiple records have been retreived with the above statement, what is the type of the variable x?

a)

Tuple

b)

List

c)

List of tuples

d)

Tuples of list

12.

Assuming mycur is a cursor object, identify the valid Python statement out of the following statements:

a)

mycur.execute("select * from student where name like "a%"")

b)

mycur.execute("select * from student where name like 'a%'")

c)

execute(mycur,"select * from student where name like 'a%'")

d)

mycur.connect("select * from student where name like 'a%'")