{"id":61940,"date":"2020-07-10T13:42:03","date_gmt":"2020-07-10T13:42:03","guid":{"rendered":"https:\/\/www.sqlshack.com\/?p=61940"},"modified":"2020-07-10T13:55:26","modified_gmt":"2020-07-10T13:55:26","slug":"sql-update-syntax-explained","status":"publish","type":"post","link":"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/","title":{"rendered":"SQL UPDATE syntax explained"},"content":{"rendered":"<p>\n    This article will get you familiar with the SQL UPDATE syntax and demonstrate how this statement can be used for<br \/>\n    modifying data using T-SQL. Data modification side of DML language in T-SQL includes three statements used for<br \/>\n    modifying data in SQL Server and those are: INSERT, UPDATE, and DELETE. The focus here will be on the UPDATE<br \/>\n    statement explicitly.\n<\/p>\n<p><!--more--><\/p>\n<h2>SQL UPDATE syntax<\/h2>\n<p>\n    So, to start with the definition, the UPDATE statement changes existing data in a table or view in SQL Server. Below<br \/>\n    is the full syntax for SQL Server and Azure SQL Database:\n<\/p>\n<pre lang=\"tsql\">[ WITH <common_table_expression> [...n] ]  \r\nUPDATE   \r\n    [ TOP ( expression ) [ PERCENT ] ]   \r\n    { { table_alias | <object> | rowset_function_limited   \r\n         [ WITH ( <Table_Hint_Limited> [ ...n ] ) ]  \r\n      }  \r\n      | @table_variable      \r\n    }  \r\n    SET  \r\n        { column_name = { expression | DEFAULT | NULL }  \r\n          | { udt_column_name.{ { property_name = expression  \r\n                                | field_name = expression }  \r\n                                | method_name ( argument [ ,...n ] )  \r\n                              }  \r\n          }  \r\n          | column_name { .WRITE ( expression , @Offset , @Length ) }  \r\n          | @variable = expression  \r\n          | @variable = column = expression  \r\n          | column_name { += | -= | *= | \/= | %= | &= | ^= | |= } expression  \r\n          | @variable { += | -= | *= | \/= | %= | &= | ^= | |= } expression  \r\n          | @variable = column { += | -= | *= | \/= | %= | &= | ^= | |= } expression  \r\n        } [ ,...n ]   \r\n  \r\n    [ <OUTPUT Clause> ]  \r\n    [ FROM{ <table_source> } [ ,...n ] ]   \r\n    [ WHERE { <search_condition>   \r\n            | { [ CURRENT OF   \r\n                  { { [ GLOBAL ] cursor_name }   \r\n                      | cursor_variable_name   \r\n                  }   \r\n                ]  \r\n              }  \r\n            }   \r\n    ]   \r\n    [ OPTION ( <query_hint> [ ,...n ] ) ]  \r\n[ ; ]  \r\n      \r\n<object> ::=  \r\n{   \r\n    [ server_name . database_name . schema_name .   \r\n    | database_name .[ schema_name ] .   \r\n    | schema_name .  \r\n    ]  \r\n    table_or_view_name}<\/pre>\n<p>\n    Don&#8217;t let the syntax scare you. We will be looking at the UPDATE statement using the minimum required syntax. The<br \/>\n    basic SQL UPDATE syntax comes down to using keyword UPDATE followed by the name of our object (table or table alias)<br \/>\n    and the SET column name equals to some values.\n<\/p>\n<p>\n    The FROM clause will come into play when we do joins and we can also have a WHERE clause when we need to update only<br \/>\n    a portion of data in a table. It goes without saying that using a WHERE in a statement is always a good idea or you<br \/>\n    might find yourself in a situation of updating every single record in a table.\n<\/p>\n<ul style=\"list-style-type: none;\">\n<li><em>For the syntax of Azure Synapse Analysis (formerly SQL Data Warehouse) and Parallel Data Warehouse, please refer to official MS documentation: <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/t-sql\/queries\/update-transact-sql?view=sql-server-ver15\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">UPDATE (Transact-SQL)<\/a><\/em><\/li>\n<\/ul>\n<p>\n    The official documentation is a treasure trove of the UPDATE statement that will take you about 40 minutes to read but has everything that you need to know in one place.\n<\/p>\n<h2>Modifying data using the UPDATE statement<\/h2>\n<p>\n    In this section, we\u2019ll be modifying data in tables from the <strong>AdventureWorks2014<\/strong> sample database.<br \/>\n    However, before we start with a simple UPDATE statement, execute a quick-select from <strong>Product <\/strong>table:\n<\/p>\n<pre lang=\"tsql\">USE AdventureWorks2014;\r\nGO\r\nSELECT *\r\nFROM Production.Product p;<\/pre>\n<p>\n    The query returns all records from the <strong>Product<\/strong> table of items that are sold or used in the<br \/>\n    manufacturing of sold products. In this table, we have a column <strong>MakeFlag<\/strong> that can be either <strong>0<\/strong> or <strong>1<\/strong> as shown below:\n<\/p>\n<p>\n    <img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2020\/07\/an-executed-select-statement-highlighting-make-fla-e1594386644668.png\"\n         alt=\"An executed SELECT statement highlighting Make Flag column in the results grid\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"\/wp-content\/uploads\/2020\/07\/an-executed-select-statement-highlighting-make-fla-e1594386644668.png\"\n         alt=\"An executed SELECT statement highlighting Make Flag column in the results grid\" \/><\/noscript>\n<\/p>\n<p>\n    <strong>0<\/strong> = Product is purchased\n<\/p>\n<p>\n    <strong>1<\/strong> = Product is manufactured in-house\n<\/p>\n<h3>Simple UPDATE statement<\/h3>\n<p>\n    Let&#8217;s now run a simple <strong>UPDATE<\/strong> statement following the SQL UPDATE syntax described earlier:\n<\/p>\n<pre lang=\"tsql\">UPDATE Production.Product\r\nSET \r\n    Production.Product.MakeFlag = 1\r\nWHERE Production.Product.ProductID = 4;<\/pre>\n<p>\n    After the execution, 1 row affected message will be returned indicating that the statement went through:\n<\/p>\n<p>\n    <img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2020\/07\/an-executed-update-statement-with-simple-sql-updat-e1594386696233.png\"\n        alt=\"An executed UPDATE statement with simple SQL UPDATE syntax showing that 1 row was affected\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"\/wp-content\/uploads\/2020\/07\/an-executed-update-statement-with-simple-sql-updat-e1594386696233.png\"\n        alt=\"An executed UPDATE statement with simple SQL UPDATE syntax showing that 1 row was affected\" \/><\/noscript>\n<\/p>\n<p>\n    Before the query was executed, the <strong>Headset Ball Bearings<\/strong> product was purchased but now it\u2019s<br \/>\n    manufactured in-house:\n<\/p>\n<p>\n    <img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2020\/07\/results-grid-with-highlighted-headset-ball-bearing.png\"\n        alt=\"Results grid with highlighted Headset Ball Bearings product and its Make Flag value\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"\/wp-content\/uploads\/2020\/07\/results-grid-with-highlighted-headset-ball-bearing.png\"\n        alt=\"Results grid with highlighted Headset Ball Bearings product and its Make Flag value\" \/><\/noscript>\n<\/p>\n<h3>Update multiple rows<\/h3>\n<p>\n    Let&#8217;s move on and look at another example to see how we can update multiple rows at once. This time, we&#8217;ll also use<br \/>\n    expressions from SQL UPDATE syntax which is a really handy way of setting a column equals to itself AKA doing<br \/>\n    something to a column on itself.\n<\/p>\n<p>\n    Use the query below to see what we have in the <strong>Employee<\/strong> table:\n<\/p>\n<pre lang=\"tsql\">SELECT *\r\nFROM HumanResources.Employee e\r\nORDER BY e.VacationHours DESC;<\/pre>\n<p>\n    The <strong>Employee<\/strong> table has information such as salary, department, title, etc. but we&#8217;re interested in the number of available vacation hours:\n<\/p>\n<p>\n    <img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2020\/07\/an-executed-select-statement-highlighting-vacation-e1594386780714.png\"\n        alt=\"An executed SELECT statement highlighting Vacation Hours column in the results grid\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"\/wp-content\/uploads\/2020\/07\/an-executed-select-statement-highlighting-vacation-e1594386780714.png\"\n        alt=\"An executed SELECT statement highlighting Vacation Hours column in the results grid\" \/><\/noscript>\n<\/p>\n<p>\n    We have a lot of different departments and job titles in the sample database, so let\u2019s run another query and filter<br \/>\n    out some of the results by saying fetch everything where the job title is e.g. Quality Assurance Technician:\n<\/p>\n<pre lang=\"tsql\">SELECT *\r\nFROM HumanResources.Employee e\r\nWHERE e.JobTitle = 'Quality Assurance Technician';<\/pre>\n<p>\n    Here we can see that we have four people with this job title and their available vacation hours:\n<\/p>\n<p>\n    <img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2020\/07\/an-executed-select-statement-highlighting-vacation-1-e1594386744419.png\"\n        alt=\"An executed SELECT statement highlighting Vacation Hours and Job Title columns in the results grid\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"\/wp-content\/uploads\/2020\/07\/an-executed-select-statement-highlighting-vacation-1-e1594386744419.png\"\n        alt=\"An executed SELECT statement highlighting Vacation Hours and Job Title columns in the results grid\" \/><\/noscript>\n<\/p>\n<p>\n    Let\u2019s just say that those guys have been performing really great for the past three months and we want to reward<br \/>\n    them by giving them a 20% increase in vacation hours. To do that, execute the query below:\n<\/p>\n<pre lang=\"tsql\">UPDATE HumanResources.Employee\r\nSET \r\n    HumanResources.Employee.VacationHours = HumanResources.Employee.VacationHours * 1.2\r\nWHERE HumanResources.Employee.JobTitle = 'Quality Assurance Technician';<\/pre>\n<p>\n    We should see a message that 4 rows are affected meaning records for those four people from the QA department have been updated:\n<\/p>\n<p>\n    <img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n            src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2020\/07\/an-executed-update-statement-with-sql-update-synta-e1594386847463.png\"\n            alt=\"An executed UPDATE statement with SQL UPDATE syntax showing that 4 rows were affected\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n            src=\"\/wp-content\/uploads\/2020\/07\/an-executed-update-statement-with-sql-update-synta-e1594386847463.png\"\n            alt=\"An executed UPDATE statement with SQL UPDATE syntax showing that 4 rows were affected\" \/><\/noscript>\n<\/p>\n<p>\n    We can check how this update reflected vacation hours by re-executing the quick-select from the <strong>Employee<\/strong> table. You\u2019ll notice that vacation hours are increased by 20 percent:\n<\/p>\n<p>\n    <img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2020\/07\/results-grid-showing-before-and-after-values-of-th.png\"\n         alt=\"Results grid showing before and after values of the Vacation Hours column\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"\/wp-content\/uploads\/2020\/07\/results-grid-showing-before-and-after-values-of-th.png\"\n         alt=\"Results grid showing before and after values of the Vacation Hours column\" \/><\/noscript>\n<\/p>\n<p>\n    Now, there\u2019s another SQL UPDATE syntax that we can use to get the exact same result. Instead of saying column name =<br \/>\n    column name, we could use the expression which looks a little better, also more meaningful for some, as shown below:\n<\/p>\n<pre lang=\"tsql\">UPDATE HumanResources.Employee\r\nSET \r\n    HumanResources.Employee.VacationHours *= 1.2\r\nWHERE HumanResources.Employee.JobTitle = 'Quality Assurance Technician';<\/pre>\n<p>\n    This is just another way to use the SET statement from the SQL UPDATE syntax and specify the list of columns or<br \/>\n    variable names to be updated.\n<\/p>\n<p>\n    It goes without saying that you can perform arithmetic operators like addition(+), subtraction(-), multiplication(*)<br \/>\n    and division(\/) on all numeric operands involved. For example, if you would like to undo changes and take that 20<br \/>\n    percent back from the previous example, well then just execute the following:\n<\/p>\n<pre lang=\"tsql\">UPDATE HumanResources.Employee\r\nSET \r\n    HumanResources.Employee.VacationHours \/= 1.2\r\nWHERE HumanResources.Employee.JobTitle = 'Quality Assurance Technician';<\/pre>\n<h3>Update data using JOIN<\/h3>\n<p>\n    After going through some basics, let\u2019s see SQL UPDATE syntax on how to do updates based on joins. This can be a<br \/>\n    really neat thing to do because a lot of times when updating data in a table we need data from another table to make<br \/>\n    desitions on what you&#8217;re updating.\n<\/p>\n<p>\n    This can be tricky at first compared to joining stuff in a SELECT statement and it&#8217;s not always straightforward, but<br \/>\n    once you get familiar with the syntax it gets easier.\n<\/p>\n<p>\n    With that in mind, let\u2019s forget the existing data in our sample database for a moment and see how to do updates<br \/>\n    using a join as simple as it gets. For this, we&#8217;ll need two new tables. Paste the code from below in the query<br \/>\n    editor and hit <strong>Execute<\/strong>:\n<\/p>\n<pre lang=\"tsql\">CREATE TABLE dbo.Bank\r\n(ID        INT NOT NULL, \r\n BankName  NVARCHAR(255) NULL, \r\n City      NVARCHAR(255) NULL, \r\n SwiftCode NVARCHAR(255) NULL, \r\n CONSTRAINT PK_Bank PRIMARY KEY CLUSTERED(ID ASC)\r\n);\r\nGO\r\nCREATE TABLE dbo.SwiftCode\r\n(ID     INT NOT NULL, \r\n BankID INT NOT NULL, \r\n Code   NVARCHAR(11) NULL, \r\n CONSTRAINT PK_SwiftCode PRIMARY KEY CLUSTERED(ID ASC)\r\n);\r\nGO<\/pre>\n<p>\n    We just created two empty tables on the <strong>dbo<\/strong> schema; <strong>Bank<\/strong> and <strong>SwiftCode<\/strong>:\n<\/p>\n<p>\n    <img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2020\/07\/successfully-executed-script-for-creating-the-bank-e1594386899677.png\"\n         alt=\"Successfully executed script for creating the Bank and Swift Code tables\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"\/wp-content\/uploads\/2020\/07\/successfully-executed-script-for-creating-the-bank-e1594386899677.png\"\n         alt=\"Successfully executed script for creating the Bank and Swift Code tables\" \/><\/noscript>\n<\/p>\n<p>\n    I entered just a few records in both tables and if we do a quick-select from both tables, here&#8217;s how it looks:\n<\/p>\n<p>\n    <img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2020\/07\/successfully-executed-script-for-retrieving-data-f.png\"\n        alt=\"Successfully executed script for retrieving data from the Bank and Swift Code tables\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"\/wp-content\/uploads\/2020\/07\/successfully-executed-script-for-retrieving-data-f.png\"\n        alt=\"Successfully executed script for retrieving data from the Bank and Swift Code tables\" \/><\/noscript>\n<\/p>\n<p>\n    As can be seen above, we\u2019re missing the <strong>SwiftCode<\/strong> information from the <strong>Bank<\/strong> table.<br \/>\n    We have this information within the <strong>SwiftCode<\/strong> table, we just need to join those two tables using<br \/>\n    <strong>BankID<\/strong> and update the <strong>Bank<\/strong> table using the information from another table.\n<\/p>\n<p>\n    So, let\u2019s look at the SQL UPDATE syntax below for achieving this:\n<\/p>\n<pre lang=\"tsql\">UPDATE b\r\nSET \r\n    b.SwiftCode = sc.Code\r\nFROM Bank b\r\n   INNER JOIN SwiftCode sc ON sc.BankID = b.id;<\/pre>\n<p>\n    Once executed, you should see a message that 4 rows are affected by this action:\n<\/p>\n<p>\n    <img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2020\/07\/successfully-executed-script-using-sql-update-synt-e1594386944962.png\"\n        \n        alt=\"Successfully executed script using SQL UPDATE syntax for updating a table using data from another table\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"\/wp-content\/uploads\/2020\/07\/successfully-executed-script-using-sql-update-synt-e1594386944962.png\"\n        \n        alt=\"Successfully executed script using SQL UPDATE syntax for updating a table using data from another table\" \/><\/noscript>\n<\/p>\n<p>\n    This means that we just updated the table by using data from another table. Cool, right? If we query the <strong>Bank<\/strong> table one more time, here\u2019s what we should have:\n<\/p>\n<p>\n    <img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2020\/07\/results-grid-showing-before-and-after-values-of-th-1.png\"\n         alt=\"Results grid showing before and after values of the Swift Code column\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\"\n        src=\"\/wp-content\/uploads\/2020\/07\/results-grid-showing-before-and-after-values-of-th-1.png\"\n         alt=\"Results grid showing before and after values of the Swift Code column\" \/><\/noscript>\n<\/p>\n<p>\n    When working on a more complex query, the rule of thumb is to always write a SELECT statement first and to just join<br \/>\n    tables together. Why? Because when you use an UPDATE, everything after the FROM is the exact same. Furthermore, it&#8217;s<br \/>\n    highly advisable to use aliases or otherwise things can get a little funky, especially on complex queries no matter<br \/>\n    how familiar you\u2019re with the SQL UPDATE syntax.\n<\/p>\n<p>\n    If you\u2019re new to SQL and don\u2019t quite understand what an alias is, by definition, aliases are temporary names to<br \/>\n    objects, so they\u2019re easier to work with when writing and reading code. I, personally, use <a href=\"https:\/\/www.apexsql.com\/sql-tools-complete.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">ApexSQL Complete<\/a> which does this for me by<br \/>\n    automatically creating aliases to SQL tables and views with it\u2019s Auto-generate aliases feature.\n<\/p>\n<h2>Conclusion<\/h2>\n<p>\n    The UPDATE statement is one of the three big statements of the DML side of the T-SQL language that deals with data<br \/>\n    modification. By the end of reading this article, hopefully, you got familiar with the SQL UPDATE syntax; we saw<br \/>\n    some basics of the statement, and how we can do an update based on joins which is a very popular and common thing to<br \/>\n    do.\n<\/p>\n<p>\n    I hope this article has been informative for you and I thank you for reading it.\n<\/p>\n<div id=\"see_more\"><\/div>\n<p><script><\/p>\n<p>    display_see_more(text = 'complete', video = 'complete', banner = 'complete', banner_link = 'complete');<\/p>\n<p><\/script><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>This article will get you familiar with the SQL UPDATE syntax and demonstrate how this statement can be used for modifying data using T-SQL. Data modification side of DML language in T-SQL includes three statements used for modifying data in SQL Server and those are: INSERT, UPDATE, and DELETE. The focus here will be on [&hellip;]<!-- AddThis Advanced Settings generic via filter on wp_trim_excerpt --><!-- AddThis Share Buttons generic via filter on wp_trim_excerpt --><\/p>\n","protected":false},"author":96,"featured_media":61947,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[408,25,194],"tags":[],"class_list":["post-61940","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dml","category-sql-commands","category-t-sql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL UPDATE syntax explained<\/title>\n<meta name=\"description\" content=\"This article explains SQL UPDATE syntax with the help of different statements of the DML side of the T-SQL language that deals with data modification\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL UPDATE syntax explained\" \/>\n<meta property=\"og:description\" content=\"This article explains SQL UPDATE syntax with the help of different statements of the DML side of the T-SQL language that deals with data modification\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Shack - articles about database auditing, server performance, data recovery, and more\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-10T13:42:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-07-10T13:55:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/07\/results-grid-showing-before-and-after-values-of-th.png\" \/>\n\t<meta property=\"og:image:width\" content=\"626\" \/>\n\t<meta property=\"og:image:height\" content=\"264\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Bojan Petrovic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bojan Petrovic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-update-syntax-explained\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-update-syntax-explained\\\/\"},\"author\":{\"name\":\"Bojan Petrovic\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#\\\/schema\\\/person\\\/e47ab8918dc7d07a441cc354ee42fc7e\"},\"headline\":\"SQL UPDATE syntax explained\",\"datePublished\":\"2020-07-10T13:42:03+00:00\",\"dateModified\":\"2020-07-10T13:55:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-update-syntax-explained\\\/\"},\"wordCount\":1239,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-update-syntax-explained\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sqlshack.com\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/results-grid-showing-before-and-after-values-of-th.png\",\"articleSection\":[\"DML\",\"SQL commands\",\"T-SQL\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-update-syntax-explained\\\/\",\"url\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-update-syntax-explained\\\/\",\"name\":\"SQL UPDATE syntax explained\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-update-syntax-explained\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-update-syntax-explained\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sqlshack.com\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/results-grid-showing-before-and-after-values-of-th.png\",\"datePublished\":\"2020-07-10T13:42:03+00:00\",\"dateModified\":\"2020-07-10T13:55:26+00:00\",\"description\":\"This article explains SQL UPDATE syntax with the help of different statements of the DML side of the T-SQL language that deals with data modification\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlshack.com\\\/sql-update-syntax-explained\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-update-syntax-explained\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.sqlshack.com\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/results-grid-showing-before-and-after-values-of-th.png\",\"contentUrl\":\"https:\\\/\\\/www.sqlshack.com\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/results-grid-showing-before-and-after-values-of-th.png\",\"width\":626,\"height\":264,\"caption\":\"Results grid showing before and after values of the Vacation Hours column\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlshack.com\\\/\",\"name\":\"SQL Shack - articles about database auditing, server performance, data recovery, and more\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlshack.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#organization\",\"name\":\"SQL Shack\",\"url\":\"https:\\\/\\\/www.sqlshack.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.sqlshack.com\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/sqlshack-default.png\",\"contentUrl\":\"https:\\\/\\\/www.sqlshack.com\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/sqlshack-default.png\",\"width\":1200,\"height\":630,\"caption\":\"SQL Shack\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#\\\/schema\\\/person\\\/e47ab8918dc7d07a441cc354ee42fc7e\",\"name\":\"Bojan Petrovic\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4e485adfc79e9de60769e887a2fa7c3aa36f14e62abc70b97014c1f9ec57bea4?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4e485adfc79e9de60769e887a2fa7c3aa36f14e62abc70b97014c1f9ec57bea4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4e485adfc79e9de60769e887a2fa7c3aa36f14e62abc70b97014c1f9ec57bea4?s=96&d=mm&r=g\",\"caption\":\"Bojan Petrovic\"},\"description\":\"Bojan aka \u201cBoksi\u201d, an AP graduate in IT Technology focused on Networks and electronic technology from the Copenhagen School of Design and Technology, is a software analyst with experience in quality assurance, software support, product evangelism, and user engagement. He has written extensively on both the SQL Shack and the ApexSQL Solution Center, on topics ranging from client technologies like 4K resolution and theming, error handling to index strategies, and performance monitoring. Bojan works at ApexSQL in Nis, Serbia as an integral part of the team focusing on designing, developing, and testing the next generation of database tools including MySQL and SQL Server, and both stand-alone tools and integrations into Visual Studio, SSMS, and VSCode. See more about Bojan at LinkedIn View all posts by Bojan Petrovic\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/bopet\\\/\"],\"url\":\"https:\\\/\\\/www.sqlshack.com\\\/author\\\/bojan-petrovic\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL UPDATE syntax explained","description":"This article explains SQL UPDATE syntax with the help of different statements of the DML side of the T-SQL language that deals with data modification","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/","og_locale":"en_US","og_type":"article","og_title":"SQL UPDATE syntax explained","og_description":"This article explains SQL UPDATE syntax with the help of different statements of the DML side of the T-SQL language that deals with data modification","og_url":"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/","og_site_name":"SQL Shack - articles about database auditing, server performance, data recovery, and more","article_published_time":"2020-07-10T13:42:03+00:00","article_modified_time":"2020-07-10T13:55:26+00:00","og_image":[{"width":626,"height":264,"url":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/07\/results-grid-showing-before-and-after-values-of-th.png","type":"image\/png"}],"author":"Bojan Petrovic","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Bojan Petrovic","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/#article","isPartOf":{"@id":"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/"},"author":{"name":"Bojan Petrovic","@id":"https:\/\/www.sqlshack.com\/#\/schema\/person\/e47ab8918dc7d07a441cc354ee42fc7e"},"headline":"SQL UPDATE syntax explained","datePublished":"2020-07-10T13:42:03+00:00","dateModified":"2020-07-10T13:55:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/"},"wordCount":1239,"commentCount":0,"publisher":{"@id":"https:\/\/www.sqlshack.com\/#organization"},"image":{"@id":"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/07\/results-grid-showing-before-and-after-values-of-th.png","articleSection":["DML","SQL commands","T-SQL"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/","url":"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/","name":"SQL UPDATE syntax explained","isPartOf":{"@id":"https:\/\/www.sqlshack.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/07\/results-grid-showing-before-and-after-values-of-th.png","datePublished":"2020-07-10T13:42:03+00:00","dateModified":"2020-07-10T13:55:26+00:00","description":"This article explains SQL UPDATE syntax with the help of different statements of the DML side of the T-SQL language that deals with data modification","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlshack.com\/sql-update-syntax-explained\/#primaryimage","url":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/07\/results-grid-showing-before-and-after-values-of-th.png","contentUrl":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2020\/07\/results-grid-showing-before-and-after-values-of-th.png","width":626,"height":264,"caption":"Results grid showing before and after values of the Vacation Hours column"},{"@type":"WebSite","@id":"https:\/\/www.sqlshack.com\/#website","url":"https:\/\/www.sqlshack.com\/","name":"SQL Shack - articles about database auditing, server performance, data recovery, and more","description":"","publisher":{"@id":"https:\/\/www.sqlshack.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlshack.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.sqlshack.com\/#organization","name":"SQL Shack","url":"https:\/\/www.sqlshack.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlshack.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2019\/03\/sqlshack-default.png","contentUrl":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2019\/03\/sqlshack-default.png","width":1200,"height":630,"caption":"SQL Shack"},"image":{"@id":"https:\/\/www.sqlshack.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.sqlshack.com\/#\/schema\/person\/e47ab8918dc7d07a441cc354ee42fc7e","name":"Bojan Petrovic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4e485adfc79e9de60769e887a2fa7c3aa36f14e62abc70b97014c1f9ec57bea4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4e485adfc79e9de60769e887a2fa7c3aa36f14e62abc70b97014c1f9ec57bea4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4e485adfc79e9de60769e887a2fa7c3aa36f14e62abc70b97014c1f9ec57bea4?s=96&d=mm&r=g","caption":"Bojan Petrovic"},"description":"Bojan aka \u201cBoksi\u201d, an AP graduate in IT Technology focused on Networks and electronic technology from the Copenhagen School of Design and Technology, is a software analyst with experience in quality assurance, software support, product evangelism, and user engagement. He has written extensively on both the SQL Shack and the ApexSQL Solution Center, on topics ranging from client technologies like 4K resolution and theming, error handling to index strategies, and performance monitoring. Bojan works at ApexSQL in Nis, Serbia as an integral part of the team focusing on designing, developing, and testing the next generation of database tools including MySQL and SQL Server, and both stand-alone tools and integrations into Visual Studio, SSMS, and VSCode. See more about Bojan at LinkedIn View all posts by Bojan Petrovic","sameAs":["https:\/\/www.linkedin.com\/in\/bopet\/"],"url":"https:\/\/www.sqlshack.com\/author\/bojan-petrovic\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/posts\/61940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/users\/96"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/comments?post=61940"}],"version-history":[{"count":5,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/posts\/61940\/revisions"}],"predecessor-version":[{"id":61954,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/posts\/61940\/revisions\/61954"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/media\/61947"}],"wp:attachment":[{"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/media?parent=61940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/categories?post=61940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/tags?post=61940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}