I want to update multiple rows in my database, the values might be different. Imagine this table:
Username FirstName LastName
-------------------------------
user1 John Doe
user2 Jane Doe
user3 bill gates
If I want to update the table so it looks like this:
Username FirstName LastName
-------------------------------
user1 John Deer
user2 Jane Farmer
user3 Gill Bates
Is it best to use one UPDATE
statement for each user? Or is it possible to do this with one query?
Also is it possible to put it in a stored procedure and provide a collection of values?
Second question is it best to check if the values are changed before doing an update? Or just update everyone even if the value is the same?
I am currently using SQL Server 2005 and C# for the application if that is relevant.
Best Answer
You can try this
Or if you want to update only changed fields
For C# client application I think usual way is to create procedure
and then call it from your application for each user