I have a stored procedure that updates two tables. The first table is always the same table, but the second table changes depending on a parameter that is passed in. Is it more efficient to write it all into one big procudure, as such
CREATE PROCEDURE MyBigProc
@id int
@param int,
@value1 int,
@value2 int
AS
BEGIN
SET NOCOUNT ON;
-- First table to update
UPDATE MyTable SET field1 = @value1 WHERE id = @id
-- Then choose which table to update based on @param
IF @param = 1
UPDATE MySecondTable SET field2 = @value2 WHERE id = @id
IF @param = 2
UPDATE MyThirdTable SET field2 = @value2 WHERE id = @id
END
Or should I write a separate procedure for each table and then call EXEC the procedure from the main procedure.
I suppose the latter is more flexible, say if I wanted to update a subtable but no the main table?