-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQL UPDATE Command.sql
32 lines (20 loc) · 825 Bytes
/
SQL UPDATE Command.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* SQL UPDATE Command */
-- UPDATE a single column with a literal value
UPDATE Person.vStateProvinceCountryRegion
SET CountryRegionName = 'United States'
WHERE CountryRegionName = 'United States of America';
-- UPDATE a single column with a formula
UPDATE Production.Product
SET ListPrice = ListPrice * 2;
-- UPDATE multiple columns of a table
UPDATE Sales.SalesPerson
SET Bonus = 6000, CommissionPct = .05, SalesQuota = NULL;
-- UPDATE a table using data from another table
UPDATE Sales.SalesPerson
SET SalesYTD = SalesYTD + so.SubTotal
FROM Sales.SalesPerson AS sp
JOIN Sales.SalesOrderHeader AS so
ON sp.BusinessEntityID = so.SalesPersonID
AND so.OrderDate = (SELECT MAX(OrderDate)
FROM Sales.SalesOrderHeader
WHERE SalesPersonID = sp.BusinessEntityID);