I have a table with unique constraint on it:
create table dbo.MyTab ( MyTabID int primary key identity, SomeValue nvarchar(50) ); Create Unique Index
Option - 3
Begin Try SET XACT_ABORT ON Begin Tran IF NOT EXISTS (Select 1 From MyTab Where SomeValue = @someValue) Begin Insert Into MyTab(SomeValue) Values ('aaa'); End Commit Tran End Try begin Catch Rollback Tran End Catch