DML — INSERT, UPDATE, DELETE — Concept Check
Questions on DML — INSERT, UPDATE, DELETE. Data Manipulation Language modifies rows; INSERT ... ON DUPLICATE KEY UPDATE, UPDATE with JOIN, and DELETE with LIMIT are common MySQL-specific DML patterns.
Questions in this quiz
8 questions on DML — INSERT, UPDATE, DELETE — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer needs to insert multiple rows into the 'products' table efficiently. What is the best approach in MySQL?
- AUse INSERT IGNORE for each row
- BUse REPLACE INTO for each row
- CUse a multi-row INSERT statement
- DUse multiple single-row INSERT statements
2.What happens when you use INSERT IGNORE on a table with a unique constraint and a duplicate key is found?
- AThe duplicate row is inserted with a warning
- BThe duplicate row is skipped without an error
- CAn error is thrown and the transaction is rolled back
- DThe existing row is updated with new values
3.A transaction updates two accounts' balances. If an error occurs after the first update, what should be done to maintain data integrity?
- ARollback the transaction
- BCommit the transaction
- CManually adjust the balances
- DIgnore the error and continue
4.A developer uses INSERT ... ON DUPLICATE KEY UPDATE. What is the primary advantage of this pattern?
- AIt always inserts a new row
- BIt atomically inserts or updates a row
- CIt prevents any duplicate keys
- DIt deletes the duplicate row
5.In MySQL, what is a safe practice when performing an UPDATE operation?
- AUse DELETE with LIMIT instead
- BUse a WHERE clause to limit affected rows
- CUpdate all rows to ensure consistency
- DAlways update without a WHERE clause
6.A DELETE operation is running slowly on a large table. What can be done to improve performance?
- AUse DELETE without a WHERE clause
- BUse INSERT IGNORE to remove rows
- CUse DELETE with JOIN
- DUse DELETE with LIMIT in a loop
7.What is the purpose of SELECT ... FOR UPDATE in a transaction?
- ATo lock rows for subsequent updates
- BTo commit the transaction immediately
- CTo rollback the transaction if needed
- DTo read data without locking
8.A developer mistakenly thinks REPLACE INTO is similar to INSERT ... ON DUPLICATE KEY UPDATE. What is a key difference?
- AREPLACE INTO only inserts new rows
- BREPLACE INTO always updates existing rows
- CREPLACE INTO deletes existing rows before inserting
- DREPLACE INTO skips duplicates