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 :: postgresql alter column nullable 
Sql :: get count by weekly pivot table sql server 
Sql :: show all tables in oracle 
Sql :: sql exclude duplicates and find even id 
Sql :: query to check cpu utilization in oracle database 
Sql :: grab all records from one table to another oracle sql 
Sql :: mysql remove last empty newline 
Sql :: how to alter table name in mysql 
Sql :: extract month from date sql two digits 
Sql :: mssql reset auto increment 
Sql :: day of the week sqlite 
Sql :: check database size in mysql 
Sql :: restart identity cascade 
Sql :: cross schema query oracle 2 users 
Sql :: liquibase update row 
Sql :: Mysql Workbench takes very long time to execute the first query 
Sql :: oracle export trigger ddl 
Sql :: table infromation in sql server 
Sql :: DUPLICATE column values 
Sql :: output to file mysql 
Sql :: sql join exists 
Sql :: connect mysql docker 
Sql :: create table mysql example auto_increment 
Sql :: truncate table 
Sql :: show all users in mysql 
Sql :: FIND OUT THE NAME HIGHEST SALARY SQL 
Sql :: SQL query to convert DD/MM/YYYY to YYYY-MM-DD 
Sql :: mysql one week ago 
Sql :: sql create table with datetime automatically 
Sql :: how to get table current identity value in sql server 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =