NoviceToDotNet
NoviceToDotNet

Reputation: 10805

roll backin all the records in sql server

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

Answers (2)

DShultz
DShultz

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

OMG Ponies
OMG Ponies

Reputation: 332581

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

Upvotes: 5

Related Questions