Wednesday, October 12, 2016

What is rollback,commit and save in SQL ?

Commit sql command use for saves the changes  on to the database.

  BEGIN TRANSACTION;
 DELETE FROM Customer
 WHERE CustomerID = 1;
 COMMIT TRANSACTION;


Rollback sql command use for rollback the transactions.

BEGIN TRAN
UPDATE Booking
SET    Name = 'k'
WHERE Booking_id = '2002'
IF @@ROWCOUNT = 1
  COMMIT TRAN
ELSE
  ROLLBACK TRAN

Savepoint use for save transaction in a certain point so that when the transaction rollback
There no need to rollback all the transaction ,just rollback the savepoint. Savepoint use
For save transaction for temporarily.

 BEGIN TRAN
INSERT INTO Student VALUES ('Tkalo')
SAVE TRAN SP              

For rollback to that certain transaction.

ROLLBACK TRAN SP
COMMIT TRAN




No comments:

Post a Comment