Reputation: 10805
My interviewer asked me Question that i am inserting 10 rows in database table and in some 5th row i find the some trouble then how can i roll back all the records?
Please let me know how can i do this
Upvotes: 1
Views: 74
Reputation: 4541
Before you insert the rows
BEGIN TRANSACTION TransactionName
[Insert Rows]
Then either
COMMIT TRANSACTION TransactionName
OR
ROLLBACK TRANSACTION TransactionName
during any problems during the insert.
Upvotes: 1
Reputation: 332581
Assuming all occur within the same transaction, use the ROLLBACK
command.
Upvotes: 5