Documente Academic
Documente Profesional
Documente Cultură
Example:
Transaction Control
Transaction Control Statements
COMMIT
ROLLBACK
COMMIT
Use the COMMIT statement to end your current transaction and make permanent all changes performed in the transaction If you do not explicitly commit the transaction and the program terminates abnormally, then the last uncommitted transaction is automatically rolled back
SYNTAX: COMMIT
ROLLBACK
Use the ROLLBACK statement to undo work done in the current transaction, or to manually undo the work done by an in-doubt distributed transaction SYNTAX: ROLLBACK
Transaction Example
BEGIN TRAN INSERT INTO EMPLOYEE (EmpId, Fname, Lname, JobId, JobLvl) VALUES ( 'HUS42628M', 'ROGER', 'SLATE,12, 25) IF(@@ERROR <> 0) ROLLBACK TRAN ELSE BEGIN DELETE FROM Jobs WHERE jobId =13 IF(@@ERROR <> 0) BEGIN PRINT 'Record not inserted in to Employee' ROLLBACK TRAN END ELSE BEGIN PRINT 'TRANSACTION SUCCESSFUL' COMMIT TRAN END END
10
12