Extended Search
Babakov.Net
Home Contacts Rules
  • Login
    Registration Forgot password?
Home Contacts Rules
  • Algorithms 0
  • Programming 2
    • C++ 0
    • .NET C# 2
    • Python 0
    • Java Script 0
  • Databases 12
    • MSSQL 10
    • Oracle 2
    • MySQL 0
  • Design 0
  • Any stuff 2
Software Developer Blogs & Notes » Tag cloud » catch
Home

Two options for executing transaction in MSSQL, each rollback by error

Two options for executing transaction in MSSQL, each rollback by error.

First option:

BEGIN TRY
    BEGIN TRAN
    UPDATE 1
    UPDATE 2 --Error
    UPDATE 3
    COMMIT TRAN
END TRY
BEGIN CATCH
    ROLLBACK TRAN
END CATCH
Databases / MSSQL
Read more
0
  • complaint
  • 2
  • 0
  • Roman from 4-09-2023, 13:01

Example, how to cath error in MSSQL

Example, how to cath error in MSSQL.

BEGIN TRY  
    -- Some code each produce ERROR.  
    SELECT 1/0;  
END TRY  
BEGIN CATCH  
    SELECT  
        ERROR_NUMBER() AS ErrorNumber  
        ,ERROR_SEVERITY() AS ErrorSeverity  
        ,ERROR_STATE() AS ErrorState  
        ,ERROR_PROCEDURE() AS ErrorProcedure  
        ,ERROR_LINE() AS ErrorLine  
        ,ERROR_MESSAGE() AS ErrorMessage;  
END CATCH;  
GO
Databases / MSSQL
Read more
2
  • complaint
  • 8
  • 0
  • Roman from 3-09-2023, 21:13

Popular articles

  1. An example of selecting a range of dates in MSSQL MSSQL
  2. Example, how to cath error in MSSQL MSSQL
  3. An example searching of procedure by text it contain MSSQL

Tags Cloud

C# catalog catch cmdshell config date dynamic error fetch folder ftp ftpd interpolated string join linux mssql numbers oracle procedure range restart rollback rows sequence serch session sevice sql string stuff text top transaction tsql ubunu update version XDocument xml xp_cmdshell
Show all tags
  • Categories
    Advanced search Latest articles Latest comments Mobile version of Website
  • Customers
    Homepage Rules Registration Statistics
  • Socials
    Telegram
Copyright © 2005–2023 Babakov.Net All Rights Reserved. Powered by Babakov Roman © 2023