Complete the code to insert a new user or update the email if the user ID already exists.
INSERT INTO users (id, name, email) VALUES (1, 'Alice', 'alice@example.com') [1];
The ON DUPLICATE KEY UPDATE clause allows updating the email if the user ID already exists.
Complete the code to update the user's name to 'Bob' if the ID already exists.
INSERT INTO users (id, name) VALUES (2, 'Bob') [1];
The ON DUPLICATE KEY UPDATE clause updates the name when the ID is a duplicate.
Fix the error in the code to update the email to 'bob@example.com' on duplicate key.
INSERT INTO users (id, email) VALUES (2, 'bob@example.com') [1];
The correct syntax is ON DUPLICATE KEY UPDATE followed by the column assignment.
Fill both blanks to insert a product or update its price and stock if the product ID exists.
INSERT INTO products (id, price, stock) VALUES ([1], 100, 50) [2] price = 100, stock = 50;
The product ID is 3, and the clause ON DUPLICATE KEY UPDATE updates price and stock if the ID exists.
Fill all three blanks to insert or update a user's name, email, and age on duplicate key.
INSERT INTO users (id, name, email, age) VALUES ([1], [2], [3], 30) ON DUPLICATE KEY UPDATE name = [2], email = [3], age = 30;
The user ID is 10, the name is 'Charlie', and the email is 'charlie@example.com'. The update clause uses the same values.