🌟 Python + MySQL Connectivity

🌟 Python + MySQL Connectivity

12th Grade

β€’

22 Qs

quiz-placeholder

Similar activities

PYTHON PROGRAMMING

PYTHON PROGRAMMING

9th - 12th Grade

β€’

20 Qs

Mysql set 1

Mysql set 1

9th - 12th Grade

β€’

21 Qs

CLASS XI - MYSQL QUIZ

CLASS XI - MYSQL QUIZ

11th - 12th Grade

β€’

20 Qs

MySQL

MySQL

12th Grade

β€’

18 Qs

SQL Commands Part 1

SQL Commands Part 1

11th - 12th Grade

β€’

20 Qs

SQL

SQL

12th Grade

β€’

20 Qs

PHP MySQL

PHP MySQL

7th Grade - Professional Development

β€’

17 Qs

Class Test

Class Test

12th Grade

β€’

20 Qs

🌟 Python + MySQL Connectivity

🌟 Python + MySQL Connectivity

Assessment

Quiz

β€’

Computers

β€’

12th Grade

β€’

Easy

Created by

Harmeet Kaur

Used 1+ times

FREE Resource

22 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec β€’ 1 pt

Which of the following is the correct method to prevent SQL injection when inserting user input into a MySQL database using PyMySQL?

Use string concatenation for query formation

Use %s placeholders in the query and pass values as a tuple

Use f-string formatting in SQL queries

Use raw input directly in the SQL query

2.

MULTIPLE CHOICE QUESTION

30 sec β€’ 1 pt

In a Python program using PyMySQL, what happens if you attempt to insert a record into a table where a NOT NULL column is left empty and no default value is set?

The record is inserted with NULL in that column

A ProgrammingError is raised by PyMySQL

A DataError is raised by the MySQL server

An IntegrityError is raised by PyMySQL

3.

MULTIPLE CHOICE QUESTION

30 sec β€’ 1 pt

Consider a table orders(order_id INT PRIMARY KEY, customer_id INT, order_date DATE) and customers(customer_id INT PRIMARY KEY, name VARCHAR(50)). Which query retrieves all orders along with customer names, ensuring that orders without a matching customer are also shown?

SELECT * FROM orders JOIN customers USING(customer_id)

SELECT * FROM orders INNER JOIN customers ON orders.customer_id = customers.customer_id

SELECT * FROM orders LEFT JOIN customers ON orders.customer_id = customers.customer_id

SELECT * FROM orders RIGHT JOIN customers ON orders.customer_id = customers.customer_id

4.

MULTIPLE CHOICE QUESTION

30 sec β€’ 1 pt

Given a PyMySQL connection object conn, how do you ensure that changes made via cursor operations are permanently saved in the database?

Use conn.save()

Call conn.commit()

Call conn.flush()

Call cursor.commit()

5.

MULTIPLE CHOICE QUESTION

30 sec β€’ 1 pt

Which of the following is NOT a valid reason for a MySQLdb._exceptions.OperationalError: (2006, "MySQL server has gone away") error?

Query execution timeout

Server closed the connection due to inactivity

Data size in a single packet exceeds max_allowed_packet

Primary key constraint violation in INSERT query

6.

MULTIPLE CHOICE QUESTION

30 sec β€’ 1 pt

In a PyMySQL program, you attempt to execute the following query: cursor.execute("SELECT * FROM flights WHERE destination = %s", "London"). What is the issue in this statement?

The placeholder %s must be replaced with the actual value before execution

The value β€œLondon” must be passed as a tuple

The query will work without any issue

The query requires a dictionary instead of a tuple for parameter passing

7.

MULTIPLE CHOICE QUESTION

30 sec β€’ 1 pt

Which of the following tasks would typically require the use of the tabulate module in a PyMySQL application?

Validating data types in a MySQL table

Displaying query results in a formatted table view in the console

Handling SQL exceptions in Python

Automating database backups

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?