SELF ASSESSMENT TEST
Multiple Choice Questions 5 Assertion and Reason Based Questions
1What is an identifier in following command? Assertion (A)and Reason (R) Type questions. Choose
i mport [Link] as db
the correct option as:
(a) import (b) mysql (a) Both Aand Rare true and Ris the correct explarnation
(c) connector (d) db for A.
9 To add a new column into a table, which command is (b) Both A and R are true and R is not correct explanation
used?
for A.
(a) ALTER TABLE (c) A is true but Ris false.
(b) UPDATE FROM
(d) A is false butRis true.
(c) INSERT INTO 14. Assertion (A) User can write Python script using
(d) All of the above [Link] library after installing Python MySQL
connector.
3 To insert multiple records into table, which method is Reason (R) It can connect to MySQL databases frorn
used to execute statements? Python.
(a) execute () 15. Assertion (A) Insert operation is required when you
want to create your records into a database's table.
(b) executemany ()
Reason (R) INSERT INTO statement is used to add a
(c) executeall ()
record.
(d) None of the above
4Which of the following statement is correct?
(a) DELETE INTO (b)DELETE TABLE 5Very Short Answer Type Questions
(c) DELETE ALL (d) DELETE FROM 16 Write the command to import the connection of Python
with MySQL.
5 It fetches all the rows of a query result. 17 Define the fetchone () method.
(a) fetchall () (b) fetchmany ()
(c) fetchwhole ( ) (d) allfetch ( ) 18 How fetchmany()method is differ from fetchall)
method?
19 Write the command to update the table Employee with
5 Fill in the Blanks Salary column, change the salary of those employee who
method of have computer skills with 35000.
6 Cursor object can be create using
connection object. 20 What do you mean by read operation?
7After creating the cursor, SQL query can be execute
.function.
5 Short Answer Type Questions
using
21 Create the connection of Python with MySQL, in which
8 Toadd a record into table, we can mention in place
database name = System
of value. User = Admin
9 We can create a table using statement. Password = Admi n@123
10 ......can connect to mysql database from Python. 22 Write the code to create a table stationery in database
School with following fields.
5State Whether True and False Fields Datatype
11. User can write Python script using [Link] I Code Varchar(3) (P)
library after installing Python MySQL connector. I Name Char(30)
12. To add single record into a table, we can mention the Int
format specifier (%s) in place of value. Qty.
Price Float
13. fetchone() returns the number of rows specified by the
size argument.
296 Allinone Computer Science Class 12th
23 Consider the table Employee whose columns' name are Conn = mysql. [Link](host=" local
E_ID, EmpName, JoiningDate, host", user="root", password=" passl23".
database"CINEMA" )
Salary, Department Cursor [Link]()
Write the code to insert thefollowing record into the [Link]("DELETE FROM THEATRE WHFRE
above table: Th ID - %5". (th_id,))
Conn. Commit)
E101 Atin 12-10-2009 35000 DBA
print([Link],"record(s) deleted ",
E102 Sandeep 7-8-1999 58000 Business Analyst [Link])
(i) What is the purpose of [Link]() in the
delete_theatre() function?
Long Answer Type Questions (a) To retrieve all records from the database
24 Consider the table FLIGHTS
(b)To execute the SQL command
FL_ No Starting Ending No _Flight No_Stops (c) Tosave changes permanently in the database
Mumbai Delhi
(d) Toclose the database connection
IC301 8
(ii) What is the role of %s in the [Link](0)
IC799 Bengluru Delhi 2 1 statement?
MC101 Indore Mumbai 3 0 (a) It is used to insert a string value directly into the
SQL query
AM812 Kanpur Bengluru 3 (b) It is a placeholder for safely inserting values and
preventing SQL injection
Write the Python code for the following (c) Itreplaces the entire SQL command
(i) Todisplay details of those flights whose number of (d) It is used to convert strings to SQL-compatible
flights greater than 5. format
(iü) To increase the number of flights of flight Indore to (iüi) Which method should Riya use to retrieve all
Mumbai by 3. records from the THEATRE table?
(a) fetchrow() (b) fetchone()
5Case Based Type Question (c) fetchall() (d) commit()
(iv) What does [Link] return after executing
25 Riya is developing a Python application for a movie a DELETE query?
theatre called Movie Magic. The application connects (a) The total number of columns in the table
to a MySQL database named CINEMA. It allows the
(b) The number of rows deleted by the query
admin to insert new theatre records, update theatre
details, delete a theatre, and display all theatres. She (c) The number of SQL statements in the script
uses the [Link] module to establish a (d) The current row being accessed
connection between Python and SQL. (v) What is the correct order of steps for performing a
" Toperform SQL operations, Riya uses: SQL query in Python using [Link]?
"connect() toconnect to the database. (a) cursor() ’ connect() ’ execute() ’ fetchall()
cursor() to create a cursor object. (b) connect() ’ cursor() ’ execute() ’
fetchall()/commit()
" execute() to run SQL commands.
(c) connect() ’ execute() ’ cursor() ’ fetchall()
" commit()to save changes like insert/update/delete. (d) execute()’ fetchall() ’ connect() ’cursor()
" fetchall)and fetchone() to retrieve data.
" %s as a placeholder in SQL queries for inserting Answers
values securely. 1. (d) 2. (a) 3. (b) 4. (d)
" rowcount to check how many rows were affected by a
5. (a) 6. cursor() 7. execute()
query.
8. Values 9. CREATE TABLE
Here's a sample function she wrote to delete a theatre 10. Mysql. connector 11. True 12. True
by its ID:
13. False 14. (a) 15.(a)
import [Link] def
delete_theatre (th_id): 25. (i) ’ (c), (i)’ (b), (ii) (c),
(iv) ’ (b), (v) ’ (b)