I've come across an efficiency problem for when a stored procedure is called to update multiple records in a single table. The actual problem contains hundreds of parameters, but here is a simplified problem.
CREATE PROCEDURE UpdateData
@ID1 int, @Value1 int,
@ID2 int, @Value2 int,
@ID3 int, @Value3 int
AS
BEGIN
-- Update record with ID1
-- Update record with ID2
-- Update record with ID3
END
I see three methods of doing this:
- Create an update query for each ID-Value pair
- Create while loop to go through all the inputs and pass them through a single update query
- Insert the inputs into a local table and do an update in a single query with use of the table created
I'm unsure at what point creating the table would be more or less efficient than the other options, as I know databases are good at doing things in parallel, but creating a temporary table also uses time.
How can I compare these three methods aside from running and timing them?
Is there a method you recommend?