From time to time my stored procedures looks like
create procedure handle_data @fk int, @value varchar(10) as begin if exists (select * from my_table where id = @fk) begin update my_table set value = @value where id = @fk end else begin insert into my_table (fk, value) select @fk, @value end end
Probably there is fault in design of app which calls this stored procedure.
Should I avoid making apps which do same stored procedure and methods for inserting new data and also updating old ones?
Is there better way to achieve updating or inserting data in one approach?
I am using SQL Server 2005 / 2008.