What is the purpose of the ROLLBACK command in SQL?
a) To undo changes made in a transaction
b) To commit changes made in a transaction
c) To delete a table from the database
d) To create a backup of the database
Answer:
a) To undo changes made in a transaction
Explanation:
The ROLLBACK command in SQL is used to undo changes made during a transaction. If a transaction encounters an error or if the changes should not be applied, ROLLBACK restores the database to its previous state, discarding all changes made in the current transaction.
ROLLBACK is crucial for maintaining data integrity in the event of a failure or mistake during a transaction. It allows the user to cancel the transaction and start over without leaving the database in an inconsistent state.
Transactions are typically wrapped between BEGIN TRANSACTION, COMMIT, and ROLLBACK commands to ensure that changes are applied only if the entire transaction is successful.