Recall & Review
beginner
What does the
REPLACE INTO statement do in MySQL?It inserts a new row into a table. If a row with the same primary key or unique key already exists, it deletes that row first and then inserts the new row.
Click to reveal answer
intermediate
How does
REPLACE INTO differ from INSERT INTO ... ON DUPLICATE KEY UPDATE?REPLACE INTO deletes the old row and inserts a new one, which can cause triggers and auto-increment values to behave differently. INSERT ... ON DUPLICATE KEY UPDATE updates the existing row without deleting it.Click to reveal answer
intermediate
What happens to auto-increment values when using
REPLACE INTO?Because
REPLACE INTO deletes the old row and inserts a new one, the auto-increment counter increases as if a new row was inserted, even if replacing an existing row.Click to reveal answer
advanced
Can
REPLACE INTO cause loss of data in some columns?Yes. Since it deletes the old row and inserts a new one, any columns not specified in the
REPLACE INTO statement will be set to their default values, potentially losing data.Click to reveal answer
beginner
When should you prefer
REPLACE INTO over INSERT INTO?Use
REPLACE INTO when you want to ensure a row is inserted or replaced entirely based on unique keys, and you want to overwrite the entire row rather than update specific columns.Click to reveal answer
What does
REPLACE INTO do if a row with the same primary key exists?✗ Incorrect
REPLACE INTO deletes the existing row with the same key and inserts the new row.Which statement is true about auto-increment values with
REPLACE INTO?✗ Incorrect
Because
REPLACE INTO deletes and inserts a row, the auto-increment counter increases.What happens to columns not specified in a
REPLACE INTO statement?✗ Incorrect
Since the old row is deleted, unspecified columns get default values on insert.
Which is a key difference between
REPLACE INTO and INSERT ... ON DUPLICATE KEY UPDATE?✗ Incorrect
REPLACE INTO deletes the old row and inserts a new one, unlike INSERT ... ON DUPLICATE KEY UPDATE.When is it best to use
REPLACE INTO?✗ Incorrect
REPLACE INTO is used to insert or fully replace a row based on unique keys.Explain how
REPLACE INTO works in MySQL and what happens to existing rows with the same key.Think about what happens if a duplicate key exists.
You got /4 concepts.
Describe the differences between
REPLACE INTO and INSERT ... ON DUPLICATE KEY UPDATE.Focus on how rows are handled differently.
You got /4 concepts.