Updating entire tables using update query

By doing this I have made sure I don’t have a bogus WHERE clause on my UPDATE statement that is going to incorrectly identify rows to be updated in my table.

In my examples above I only updated a single column with my UPDATE statement.

There may be times when you don’t want to manually write a bunch of UPDATE statements with different literal strings to update your table.

Suppose I wanted to change all the prices of my Toys with a single UPDATE statement.

I then used the New Toy Price column values for Toy Name and Price to update my Toy table column values on rows that have matching column ID values.

We have already seen how to limit the rows being updated by using the WHERE clause.

There are multiple ways to use the UPDATE statement to update a SQL Server table.

In my first TSQL script above, when I create the TOY table, there is typo in the first Toy Name.

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.

To update the row that was found I used the “SET” clause of the UPDATE statement, which set the new Toy Name to the correct spelling of “Magic Wand”.