Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Transaction in SQL

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 45
    Comment on it

    Transaction anywhere is used to execute or stop set of statements.

         BEGIN TRANSACTION trans
        BEGIN TRY
        INSERT INTO Department(DeptID,DeptName,Location)VALUES(2,'HR','Delhi')
        INSERT INTO Employee(EmpID,Name,Salary,Address,DeptID)VALUES(1,'Mohan',18000,'Delhi',1)
         IF @@TRANCOUNT > 0
         BEGIN COMMIT TRANSACTION trans
         END
        END TRY
        BEGIN CATCH
         print 'Error Occured'
         IF @@TRANCOUNT > 0
         BEGIN ROLLBACK TRANSACTION trans 
         END
        END CATCH 

     

    Save point is used in transaction  to set data to a particular point . We call it rollback

    BEGIN TRY
    INSERT INTO Department(DeptID,DeptName,Location)VALUES(2,'HR','Delhi')
    IF @@TRANCOUNT > 0
     BEGIN SAVE TRANSACTION trans;
     END
    INSERT INTO Department(DeptID,DeptName,Location)VALUES(3,'Admin','Delhi') 
    INSERT INTO Employee(EmpID,Name,Salary,Address,DeptID)VALUES(1,'Mohan',18000,'Delhi',1)
    IF @@TRANCOUNT > 0
     BEGIN COMMIT TRANSACTION trans
     END
    END TRY
    BEGIN CATCH
     print 'Error Occured'
    IF @@TRANCOUNT > 0
     BEGIN ROLLBACK TRANSACTION trans
     END
    END CATCH 

     

     

    SQL Server

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: