views:

36

answers:

2

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

+5  A: 

Assuming all occur within the same transaction, use the ROLLBACK command.

OMG Ponies
I wish I could upvote this twice, once for the right answer and another for the lol I had when I read your name. :-D
Dave
really funny :)
NoviceToDotNet
+1  A: 

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.

DShultz
it will automatically roll back if there arise any error
NoviceToDotNet