Sql updating multiple rows with different values
In order to update a row in a SQL Server table you will use the UDPATE statement.In this article I will show you a number of different ways to use the UPDATE statement to modify the data in your SQL Server tables.Unfortunately it’s not as easy as inserting, but once you see what’s being done you will probably say “Oh, of course! The key to the multiple row update query is the CASE statement.My SQL’s CASE reference page doesn’t even have the word “UPDATE” on the page anywhere, but don’t let that fool you, it can be used in UPDATE statements!There are multiple ways to use the UPDATE statement to update a SQL Server table.In this article I will show you the most common methods of using the UPDATE statement.I’ve had to figure this out on my own twice now, so I guess it’s time to document it.It is possible, and fairly easy, to update multiple rows of a My SQL table at the same time, with different values for each row.
Here is an example solution I implemented for updating (this is obviously a sloppy and very inflexible solution, but it's merely an example) I'll be glad to fully code the solution and create a PR if you feel this would be a valuable and acceptable feature for the Query Builder API. @barryvdh You're correct that it would only be for updating the same columns for all models.
I created a Toy Name of “Magic Wnd” when it should have been “Magic Wand”.
To update this single row I can run the following UPDATE statement: the UPDATE statement was able to find the one row in my Toy table that had the misspelled Toy Name.
The ELSE case will let us keep the original value if we don’t explicitly provide one.
The WHERE will limit our updates to the rows we are trying to update.