Friday, November 07, 2014

TSQL Tutorial : Updating Data

Most people eventually want to change the data they've loaded into a database.
The SQL UPDATE command is the means by which this happens. Here's an example:
UPDATE customers
SET Zip='86753-0900'
WHERE City='Reo'
Depending on the data, the WHERE clause in this query might limit the UPDATE to a single row or to many
You can update all the rows in a table by omitting the WHERE clause:
UPDATE customers
SET State='CA'
You can also update a column using columns in the same table, including the column itself, like so:
UPDATE orders
SET Amount=Amount+(Amount*.07)
Transact-SQL provides a nice extension, the SQL UPDATE command, that allows you to update the values
In one table with those from another. Here's an example:
SET Amount=Price
FROM orders o JOIN items i ON (o.ItemNumber=i.ItemNumber)

TSQL Tutorial...

No comments:

Post a Comment