Quiz on Database Access in Python
Quiz on Database Access in Python
by
PythonGeeks Team
Master Programming with Our Comprehensive Courses Enroll Now!
0 of 15 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
You must sign in or sign up to start the quiz.
You must first complete the following:
Quiz complete. Results are being recorded.
0 of 15 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0 )
Earned Point(s): 0 of 0 , (0 )
0 Essay(s) Pending (Possible Point(s): 0 )
Show Question
1
Show Question
2
Show Question
3
Show Question
4
Show Question
5
Show Question
6
Show Question
7
Show Question
8
Show Question
9
Show Question
10
Show Question
11
Show Question
12
Show Question
13
Show Question
14
Show Question
15
Review / Skip
Answered
Correct
Incorrect
Question 1 of 15
Which of the following is not the module provided by Python to connect with MySQL?
Question 2 of 15
Which of the following commands is used to stop the connection between Python and Mysql?
Question 3 of 15
Arrange the below steps in order to communicate with the database?
1. Get connection object using the connect()
2. Use the execute() function by passing query
3. Call the cursor() method
Question 4 of 15
What does ‘R’ mean in CRUD?
Question 5 of 15
What does the below code do?
import mysql.connector
db=mysql.connector.connect(user=”root”,passwd=”1234″,host=”localhost”)
my_cursor=db.cursor()
my_cursor.execute(“CREATE DATABASE db”)
db=mysql.connector.connect(user=”root”,passwd=”1234″,host=”localhost”,database=’d_b’)
my_cursor=db.cursor()
query=”CREATE TABLE food”
my_cursor.execute(query)
Question 6 of 15
Which of the following is the correct code to add a column named ‘clmn’ to the table ‘tab’ that is a primary key?
Question 7 of 15
What is the output of the below code, the database db exists in the server?
import mysql.connector
db=mysql.connector.connect(user=”root”,passwd=”1234″,host=”localhost”,database=’db’)
my_cursor=db.cursor()
query=”CREATE TABLE tb(cl1 INT(10),cl2 VARCHAR(255), cl3 INT(10))”
my_cursor.execute(query)
my_cursor.execute(“INSERT INTO tb(cl1,cl2,cl3) VALUES(1,’a’,6)”)
db.commit()
print(my_cursor.rowcount)
Question 8 of 15
Which of the following commands is used to get all the tables in the database?
Question 9 of 15
What does the below command do, if the table name tb and it has 5 records?
query = “SELECT * FROM tb”
my_cursor.execute(query)
print(my_cursor.fetchone())
Question 10 of 15
Which of the following command inserts multiple records at once into the table tb containing 3 columns cl1,cl2,cl3?
my_cursor.executemany("INSERT INTO tb(cl1,cl2,cl3)
VALUES(%s,%s,%s)",[(1,'r',5),(2,'a',9)])
Correct
Incorrect
Correct answer
my_cursor.executeall("INSERT INTO tb(cl1,cl2,cl3)
VALUES(%s,%s,%s)",[(1,'r',5),(2,'a',9)])
Correct
Incorrect
Correct answer
my_cursor.executemultiple("INSERT INTO tb(cl1,cl2,cl3)
VALUES(%s,%s,%s)",[(1,'r',5),(2,'a',9)])
Correct
Incorrect
Correct answer
Question 11 of 15
What is the following code select from table tb containing 3 columns cl1,cl2,cl3?
query = “SELECT cl1 FROM tb WHERE cl1>1”
my_cursor.execute(query)
Question 12 of 15
Which of the following is the correct way to delete all the information from the table tb?
Question 13 of 15
Which of the following is the correct command to change all the value of the cl3 to 1 from table tb containing 3 columns cl1,cl2,cl3?
Question 14 of 15
What is the function of the below code from table tb containing 3 columns cl1,cl2,cl3?
query = “DELETE FROM tb WHERE cl1 = 1”
my_cursor.execute(query)
Question 15 of 15
Which of the following commands is used to delete a table?
Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google | Facebook
PythonGeeks Team
The PythonGeeks Team offers industry-relevant Python programming tutorials, from web development to AI, ML and Data Science. With a focus on simplicity, we help learners of all backgrounds build their coding skills.