Monthly Archives: April 2018

Idempotent (run twice safe) sql statements

if (select count(*) from neatoSchema.YourTable where SomeColumnYouCanCheckDataOn = 2018)> 0
begin
print 'That row is already inserted'
end
else
begin
INSERT into neatoSchema.[ConferenceDate]
(... your data ...)
end

You can also interrogate information_schema.tables or information_schema.columns if you are doing a change to a table to ensure that doesn’t run twice!