Self Studies

Interface Python with SQL Database Test - 1

Result Self Studies

Interface Python with SQL Database Test - 1
  • Score

    -

    out of -
  • Rank

    -

    out of -
TIME Taken - -
Self Studies

SHARING IS CARING

If our Website helped you a little, then kindly spread our voice using Social Networks. Spread our word to your readers, friends, teachers, students & all those close ones who deserve to know what you know now.

Self Studies Self Studies
Weekly Quiz Competition
  • Question 1
    1 / -0.25

    Mandatory arguments required to connect any database from Python

    Solution

    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)

  • Question 2
    1 / -0.25

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

    Solution

    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)

  • Question 3
    1 / -0.25

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

    Solution

    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)

  • Question 4
    1 / -0.25

    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?

    Solution

    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)

  • Question 5
    1 / -0.25

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

    Solution

    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)

  • Question 6
    1 / -0.25

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

    Solution

    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.

  • Question 7
    1 / -0.25

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

    Solution

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

  • Question 8
    1 / -0.25

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

    Solution

    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)

  • Question 9
    1 / -0.25

    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?

    Solution

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

  • Question 10
    1 / -0.25

    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:

    Solution

    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)

Self Studies
User
Question Analysis
  • Correct -

  • Wrong -

  • Skipped -

My Perfomance
  • Score

    -

    out of -
  • Rank

    -

    out of -
Re-Attempt Weekly Quiz Competition
Self Studies Get latest Exam Updates
& Study Material Alerts!
No, Thanks
Self Studies
Click on Allow to receive notifications
Allow Notification
Self Studies
Self Studies Self Studies
To enable notifications follow this 2 steps:
  • First Click on Secure Icon Self Studies
  • Second click on the toggle icon
Allow Notification
Get latest Exam Updates & FREE Study Material Alerts!
Self Studies ×
Open Now