Updating entire tables using update query
Below is an example that does this: I updated the Toy Name and the Price for the Toy row with an ID value of 4, which was my original Super Surfer row.
I did this by having a single SET clause in my UPDATE statement, with the two column name/value pairs separated with a comma.
Additionally if you forget the WHERE clause altogether, you will update the entire table when you might not intend to.
Here is an example where I specified the WHERE clause incorrectly and I updated too many rows: Here I updated Toy Name on two rows, the “Silver Magic” and the “Super Surfer” Toyname rows.
By doing this I can see what my WHERE condition will return to make sure it identifies the same rows I want to update.
To accomplish that I joined the TOY table to my New Toy Price table based on the ID column.
If you want to review the complete syntax of the UPDATE statement then please refer to Books Online.
To properly show you how to use the UPDATE statement I will need to create a few tables to hold some sample data. Below is the code to create my Toy table: In order to show you how to UPDATE a table from data in another table I need to build a second sample data table that I will call New Toy Price.
In this article I will show you the most common methods of using the UPDATE statement.
Below is the basic syntax for the UPDATE statement: This is not the complete syntax of the update 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.