MySQL Database Quiz Questions

Course Name:MySQL
Chapter Name:Chapter 6 - DML (Data Manipulation Language)
Lesson Content Link:UPSERT
Current Quiz Count:30
Progress
0%
Q1
True / False

In MySQL, the term UPSERT refers to an operation that inserts a new row or updates an existing row if a duplicate key is found.

Q2
True / False

The INSERT IGNORE statement in MySQL can be used to perform an UPSERT operation.

Q3
True / False

In MySQL, the REPLACE INTO statement can be used to achieve similar functionality as UPSERT by deleting the existing row with the same primary key and inserting a new one.

Q4
True / False

The INSERT ... ON DUPLICATE KEY UPDATE statement in MySQL is a common way to perform an UPSERT operation.

Q5
True / False

When using INSERT ... ON DUPLICATE KEY UPDATE in MySQL, if no duplicate key is found, only an update operation is performed.

Q6
True / False

The INSERT ... ON DUPLICATE KEY UPDATE statement in MySQL can only be used with tables that have primary keys.

Q7
True / False

In MySQL, the ON DUPLICATE KEY UPDATE clause can be used to conditionally update certain columns based on the values of other columns.

Q8
True / False

Using INSERT ... ON DUPLICATE KEY UPDATE in MySQL can result in both insert and update operations being logged in the binary log if binary logging is enabled.

Q9
True / False

MySQL's INSERT ... ON DUPLICATE KEY UPDATE statement can be used with partitioned tables.

Q10
True / False

In MySQL, the ON DUPLICATE KEY UPDATE clause can include multiple column updates separated by commas.

Q11
Single Choice

What does the UPSERT operation in MySQL do?

Q12
Single Choice

Which MySQL statement is used to perform an UPSERT operation

Q13
Single Choice

MySQL, which clause can you use to handle duplicates during an insert operation?

Q14
Single Choice

Which of the following MySQL features allows you to perform an UPSERT operation when a unique key conflict occurs?

Q15
Single Choice

What does the following MySQL statement do?

SQL Code
INSERT INTO users (id, name) VALUES (1, 'John') ON DUPLICATE KEY UPDATE name='John';
Q16
Single Choice

Which of the following MySQL statements correctly performs an UPSERT operation?

Q17
Single Choice

How does MySQL handle an UPSERT operation when using the ON DUPLICATE KEY UPDATE clause and there are multiple unique constraints?

Q18
Single Choice

Consider the following MySQL table structure:

SQL Code
CREATE TABLE products (
 product_id INT PRIMARY KEY,
 product_name VARCHAR(100),
 price DECIMAL(10,2),
 UNIQUE (product_name)
);
What will happen if you run the following UPSERT statement?
INSERT INTO products (product_id, product_name, price) VALUES (1, 'Laptop', 999.99)
ON DUPLICATE KEY UPDATE price=999.99;
Q19
Single Choice

Which MySQL statement is equivalent to performing an UPSERT operation using INSERT ... ON DUPLICATE KEY UPDATE but deletes the existing row before insertion?

Q20
Single Choice

MySQL, what will be the result of the following UPSERT operation when the table employees has a unique constraint on the email column?

SQL Code
INSERT INTO employees (id, name, email) VALUES (2, 'Alice', 'alice@example.com')
ON DUPLICATE KEY UPDATE name = 'Alice';
Q21
Multiple Choice

Identify the correct SQL statement to perform an UPSERT operation using INSERT...ON DUPLICATE KEY UPDATE.

SQL Code
INSERT INTO users (user_id, username, email)
VALUES (1, 'jdoe', 'jdoe@example.com')
ON DUPLICATE KEY UPDATE email = 'jdoe@example.com';
Q22
Multiple Choice

Choose the correct SQL statement to perform an UPSERT operation using REPLACE INTO.

SQL Code
REPLACE INTO products (product_id, product_name, price)
VALUES (1, 'Laptop', 1500);
Q23
Multiple Choice

Determine the correct SQL statement to update existing data or insert a new row if no matching data is found.

SQL Code
INSERT INTO inventory (item_id, stock)
VALUES (1001, 50)
ON DUPLICATE KEY UPDATE stock = stock + 50;
Q24
Multiple Choice

Which SQL statement correctly performs an UPSERT operation when dealing with multiple rows of data?

SQL Code
INSERT INTO orders (order_id, order_date, total)
VALUES (1, '2024-01-01', 500),
(2, '2024-01-02', 750)
ON DUPLICATE KEY UPDATE total = VALUES(total);
Q25
Multiple Choice

Select the correct SQL statement to insert or update a row while setting a default value if the row does not exist.

SQL Code
INSERT INTO settings (setting_name, setting_value)
VALUES ('theme', 'dark')
ON DUPLICATE KEY UPDATE setting_value = 'dark';
Q26
Multiple Choice

Determine the correct SQL statement to perform an UPSERT operation with a calculated value in the UPDATE clause.

SQL Code
INSERT INTO accounts (account_id, balance)
VALUES (101, 500)
ON DUPLICATE KEY UPDATE balance = balance + 500;
Q27
Multiple Choice

Which SQL statement correctly uses the INSERT...ON DUPLICATE KEY UPDATE syntax to handle a unique constraint violation?

SQL Code
INSERT INTO email_subscribers (email, subscription_date)
VALUES ('user@example.com', '2024-01-01')
ON DUPLICATE KEY UPDATE subscription_date = '2024-01-01';
Q28
Multiple Choice

Identify the correct SQL statement to perform an UPSERT operation that increments a counter in the UPDATE clause.

SQL Code
INSERT INTO page_views (page_id, view_count)
VALUES (1, 1)
ON DUPLICATE KEY UPDATE view_count = view_count + 1;
Q29
Multiple Choice

Select the correct SQL statement to perform an UPSERT operation using INSERT IGNORE.

SQL Code
INSERT IGNORE INTO orders (order_id, customer_id, order_date)
VALUES (1, 101, '2024-01-01');
Q30
Multiple Choice

Determine the correct SQL statement to perform an UPSERT operation that conditionally updates only if a column has a specific value.

SQL Code
INSERT INTO products (product_id, stock)
VALUES (101, 50)
ON DUPLICATE KEY UPDATE stock = CASE
WHEN stock < 50 THEN stock + 50
ELSE stock END;