Preview Content - log in or become a member

SQL Update

Hi

In this tutorial I will give you example of SQL Update queries which will include SQL update join examples. I will use SQL Server 2008 R2 for my samples which should work with previous version of SQL Server without any problems.

Contents

SQL Update Overview


SQL Update is used to update one table columns with specified values. You can update one or multiple columns at the same time. For instance you might want to update customer address and this case you would update several columns like AddressLine1, AddressLine2, City, Post code with usually either hard coded or provided values from end user application. You could also update values using calculated fields for instance you might want to update Employee holiday entitlement (once a year) and you could use Employee start date to calculate number of years that employee has worked for the company and use some "IF" (case in SQL) logic to specify the correct holiday entitlement. Very often you might want to perform updates using another related table and for instance in our Holiday entitlement case we could use a HolidayEntitlement table and match it against our YearsWorked that could be calculated using EmployeeStartDate and provide matching row (HolidayEntitlement) from related HolidayEntitlement table. This SQL Update Join that I will give you examples of but be careful with joins this method can be tricky and I will give examples when it can go wrong. Apart from specifing or matching rows in SQL Update the most common task is to specify correct filter (or join) so we update only the rows with values we want to affect. Below I will provide you with simple syntax and later on provide you examples that will cover types of updates I mentioned.

SQL Update Syntax

Below I will give you basic and most popular example of SQL Update syntax which should work in most cases but there are more complicated syntaxes and I will show them to you with examples and screenshots later in this section.

 



For full access Log In or become a member

Plans:
Bronze
Silver
Gold
6 Courses
T-SQL (3), SSRS (1), SSIS(1), Excel (1)
Watch Video
75 Mini Courses
T-SQL (34), SSRS (7), SSIS(16), + more
300+ videos and 300+ Articles
38
(part of
Courses)
Progress Tracking
21 Interview Q&As pages
T-SQL (8), SSRS (3), SSIS(4), Other (6)
Forum
11 Webinar Recordings
T-SQL (1), SSRS (9), Career(1)
1 DIY Project (beta)
70-461 Tests
Watch Video
60 days, 100% Money Back Guarantee
Instant Activation
Currency: USD*
* You can change currency at checkout.
Duration:
Bronze
Silver
Gold
1 month $19
sign up
$24
sign up
$29
sign up
3 months 33% off
(2 months + 1 free)
$39
sign up
$50
sign up
$60
sign up
6 months 40% off
(3.6 months + 2.4 free)
$68
sign up
$86
sign up
$104
sign up
1 year 50% off
(6 months + 6 free)
$114
sign up
$144
sign up
$174
sign up
2 years 60% off
(9.6 months + 14.4 free)
$182
sign up
$230
sign up
$278
sign up
lifetime >60% off
(12.5 months + a lot for free)
$239
sign up
$302
sign up
$365
sign up


Did you find this page useful?
+5  |  -0
(5 Votes)