Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql try catch

BEGIN TRY
  SELECT 1 / 0 AS Error;
END TRY
BEGIN CATCH
  SELECT
    ERROR_NUMBER() AS ErrorNumber,
    ERROR_STATE() AS ErrorState,
    ERROR_SEVERITY() AS ErrorSeverity,
    ERROR_PROCEDURE() AS ErrorProcedure,
    ERROR_LINE() AS ErrorLine,
    ERROR_MESSAGE() AS ErrorMessage;
END CATCH;
Comment

try catch sql transaction

BEGIN TRANSACTION [Tran1]            
BEGIN TRY           
-- sql statements(update/insert...)     
COMMIT TRANSACTION [Tran1]      
END TRY      
      
BEGIN CATCH      
ROLLBACK TRANSACTION [Tran1]      
SELECT ERROR_MESSAGE() AS ErrorMessage;      
END CATCH     
Comment

try catch sql

-- It is Transaction Control Language(TCL)
-- case1 (temporary)
BEGIN TRANSACTION
-- perform DML operation i.e. INSERT, UPDATE, DELETE
ROLLBACK -- goes to previous state 

-- case2 (permanent)
BEGIN TRANSACTION
-- perform DML operation i.e. INSERT, UPDATE, DELETE
COMMIT -- Transaction is executed and hence change is done permanently
Comment

PREVIOUS NEXT
Code Example
Sql :: ignore case in string sql 
Sql :: stuff sql server 
Sql :: array of objects sql 
Sql :: select database in mysql 
Sql :: drop database using terminal postgres 
Sql :: select into 
Sql :: sql server today minus n 
Sql :: login failed for login due to trigger execution 
Sql :: sqlite select split string 
Sql :: mysql count unique in group statement 
Sql :: how to connect to postgres 
Sql :: oracle get ddl 
Sql :: sql query inner join 3 tables 
Sql :: sql query to create table in database 
Sql :: import mysql database command line 
Sql :: mysql limit order by 
Sql :: mysql update command 
Sql :: union all query in sql 
Sql :: sql pivot rows to columns 
Sql :: datagrip exec 
Sql :: An error occurred while installing mysql (2.9.1), and Bundler cannot continue 
Sql :: mysql server not running 
Sql :: mysqli auto increment id 
Sql :: mysql size of database 
Sql :: docker hub mysql 
Sql :: lost connection to mysql server during query when dumping table 
Sql :: mysql extract day from date leading zero 
Sql :: sql highest salary by location 
Sql :: left join in sql oracle 
Sql :: sqlite create record 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =