I have this TSQL code that checks if the ‘sadsadsad’ exists and if not inserts it into the table.
if not exists(select id from [ua_subset_composite] where ua = 'sadsadsad')
begin
insert into [ua_subset_composite]
select 'sadsadsad',1,null,null,null,null
end
My concern is that in production where there will be multiple threads running concurrently, a situation may occur that a record will slip thru between the not exists select and the insert.
I don’t want to add a unique constraint on the column and wondering if I can improve this SQL code so that it will guarantee the uniqueness
This is what I have ended up doing
To test the code I ran this code concurrently from multiple windows