0
0
MySQLquery~5 mins

REPLACE INTO behavior in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ADeletes the old row and inserts the new row
BUpdates the existing row without deleting
CIgnores the new row
DThrows an error
Which statement is true about auto-increment values with REPLACE INTO?
AAuto-increment value stays the same
BAuto-increment value decreases
CAuto-increment value increases as if a new row was inserted
DAuto-increment value resets to zero
What happens to columns not specified in a REPLACE INTO statement?
AThey are ignored
BThey keep their old values
CThey cause an error
DThey are set to default values
Which is a key difference between REPLACE INTO and INSERT ... ON DUPLICATE KEY UPDATE?
A<code>REPLACE INTO</code> deletes and reinserts rows
B<code>REPLACE INTO</code> updates rows without deleting
C<code>INSERT ... ON DUPLICATE KEY UPDATE</code> deletes rows
DBoth behave exactly the same
When is it best to use REPLACE INTO?
AWhen you want to update only some columns
BWhen you want to insert or fully replace a row
CWhen you want to ignore duplicates
DWhen you want to delete rows
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.