Ms sql updating one table from another

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”.

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”.

By doing this I can see what my WHERE condition will return to make sure it identifies the same rows I want to update.

Once my SELECT statement does return the correct rows I can then copy the WHERE clause from my SELECT statement, and paste it into my UDPATE statement code.

There may be times when you need to write some code to update a row, or set of rows in a table.

Suppose I wanted to change all the prices of my Toys with a single 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.

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

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.

Leave a Reply