USE DB_MyTesting
DECLARE @intErrorCode INT
BEGIN TRAN
UPDATE Employee
SET Phone = '415 354-9866'
WHERE EId= '12'
SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM
UPDATE Employee
SET city = 'Hyderabad', country = 'India'
WHERE EId='13'
SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM
COMMIT TRAN
PROBLEM:
IF (@intErrorCode <> 0) BEGIN
PRINT 'Unexpected error occurred!'
ROLLBACK TRAN
END
DECLARE @intErrorCode INT
BEGIN TRAN
UPDATE Employee
SET Phone = '415 354-9866'
WHERE EId= '12'
SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM
UPDATE Employee
SET city = 'Hyderabad', country = 'India'
WHERE EId='13'
SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM
COMMIT TRAN
PROBLEM:
IF (@intErrorCode <> 0) BEGIN
PRINT 'Unexpected error occurred!'
ROLLBACK TRAN
END
No comments:
Post a Comment