Q1
True / FalseIn MySQL, the term UPSERT refers to an operation that inserts a new row or updates an existing row if a duplicate key is found.
UPSERT is a combination of "UPDATE" and "INSERT". In MySQL, it allows for inserting a new row or updating an existing row if a conflict occurs due to a duplicate key.
Q2
True / FalseThe INSERT IGNORE statement in MySQL can be used to perform an UPSERT operation.
INSERT IGNORE ignores duplicate key errors but does not update existing rows. It only inserts new rows without causing an error if a duplicate key is found.
Q3
True / FalseIn 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.
The REPLACE INTO statement deletes the existing row with the same primary key and inserts a new row, achieving a similar result to an UPSERT operation.
Q4
True / FalseThe INSERT ... ON DUPLICATE KEY UPDATE statement in MySQL is a common way to perform an UPSERT operation.
The INSERT ... ON DUPLICATE KEY UPDATE statement allows for inserting a row or updating it if a duplicate key is found, making it a typical way to perform an UPSERT in MySQL.
Q5
True / FalseWhen using INSERT ... ON DUPLICATE KEY UPDATE in MySQL, if no duplicate key is found, only an update operation is performed.
If no duplicate key is found, an insert operation is performed. The update operation only occurs if a duplicate key is found.
Q6
True / FalseThe INSERT ... ON DUPLICATE KEY UPDATE statement in MySQL can only be used with tables that have primary keys.
The INSERT ... ON DUPLICATE KEY UPDATE statement can be used with tables that have unique keys as well as primary keys.
Q7
True / FalseIn MySQL, the ON DUPLICATE KEY UPDATE clause can be used to conditionally update certain columns based on the values of other columns.
The ON DUPLICATE KEY UPDATE clause allows for complex expressions and conditions to update certain columns based on the values of other columns.
Q8
True / FalseUsing 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.
Both insert and update operations are logged in the binary log if binary logging is enabled, making it possible to replicate the exact sequence of events.
Q9
True / FalseMySQL's INSERT ... ON DUPLICATE KEY UPDATE statement can be used with partitioned tables.
The INSERT ... ON DUPLICATE KEY UPDATE statement is fully compatible with partitioned tables in MySQL.
Q10
True / FalseIn MySQL, the ON DUPLICATE KEY UPDATE clause can include multiple column updates separated by commas.
The ON DUPLICATE KEY UPDATE clause allows multiple column updates, and each column update is separated by a comma.
Q21
Multiple ChoiceIdentify 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';
This UPSERT operation inserts a new row or updates the existing row if a duplicate key (user_id) is found.
Q22
Multiple ChoiceChoose 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);
REPLACE INTO first deletes the existing row with a matching primary key (if any) and then inserts the new row.
Q24
Multiple ChoiceWhich 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);
This SQL statement attempts to insert multiple rows and updates the total if the order_id already exists.
Q29
Multiple ChoiceSelect 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');
The INSERT IGNORE statement ignores any errors caused by duplicate keys, effectively performing an UPSERT without updating existing rows.