{"id":724,"date":"2018-07-31T09:32:50","date_gmt":"2018-07-31T02:32:50","guid":{"rendered":"http:\/\/www.sqlservertutorial.net\/?page_id=724"},"modified":"2020-04-11T20:13:17","modified_gmt":"2020-04-11T13:13:17","slug":"sql-server-merge","status":"publish","type":"page","link":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/","title":{"rendered":"SQL Server MERGE"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the SQL Server <code>MERGE<\/code> statement to update data in a table based on values matched from another table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-sql-server-merge-statement'>Introduction SQL Server MERGE Statement <a href=\"#introduction-sql-server-merge-statement\" class=\"anchor\" id=\"introduction-sql-server-merge-statement\" title=\"Anchor for Introduction SQL Server &lt;code&gt;MERGE&lt;\/code&gt; Statement\">#<\/a><\/h2>\n\n\n\n<p>Suppose, you have two table called source and target tables, and you need to update the target table based on the values matched from the source table. There are three cases:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>The source table has some rows that do not exist in the target table. In this case, you need to <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-insert\/\">insert<\/a> rows that are in the source table into the target table.<\/li><li>The target table has some rows that do not exist in the source table. In this case, you need to <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-delete\/\">delete<\/a> rows from the target table.<\/li><li>The source table has some rows with the same keys as the rows in the target table. However, these rows have different values in the non-key columns. In this case, you need to <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-update\/\">update<\/a> the rows in the target table with the values coming from the source table.<\/li><\/ol>\n\n\n\n<p>The following picture illustrates the source and target tables with the corresponding actions: insert, update, and delete:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"659\" height=\"377\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-MERGE.png\" alt=\"SQL Server MERGE\" class=\"wp-image-726\" srcset=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-MERGE.png 659w, https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-MERGE-300x172.png 300w\" sizes=\"auto, (max-width: 659px) 100vw, 659px\" \/><\/figure>\n\n\n\n<p>If you use the <code><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-insert\/\">INSERT<\/a><\/code>, <code><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-update\/\">UPDATE<\/a><\/code>, and <code><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-delete\/\">DELETE<\/a><\/code> statement individually, you have to construct three separate statements to update the data to the target table with the matching rows from the source table.<\/p>\n\n\n\n<p>However, SQL Server provides the <code>MERGE<\/code> statement that allows you to perform three actions at the same time. The following shows the syntax of the <code>MERGE<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">MERGE<\/span> target_table <span class=\"hljs-keyword\">USING<\/span> source_table\n<span class=\"hljs-keyword\">ON<\/span> merge_condition\n<span class=\"hljs-keyword\">WHEN<\/span> <span class=\"hljs-keyword\">MATCHED<\/span>\n    <span class=\"hljs-keyword\">THEN<\/span> update_statement\n<span class=\"hljs-keyword\">WHEN<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">MATCHED<\/span>\n    <span class=\"hljs-keyword\">THEN<\/span> insert_statement\n<span class=\"hljs-keyword\">WHEN<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">MATCHED<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-keyword\">SOURCE<\/span>\n    <span class=\"hljs-keyword\">THEN<\/span> <span class=\"hljs-keyword\">DELETE<\/span>;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>First, you specify the target table and the source table in the <code>MERGE<\/code> clause.<\/p>\n\n\n\n<p>Second, the <code>merge_condition<\/code> determines how the rows from the source table are matched to the rows from the target table. It is similar to the join condition in the <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-joins\/\">join<\/a> clause. Typically, you use the key columns either <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-primary-key\/\">primary key<\/a> or <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-unique-constraint\/\">unique key<\/a> for matching.<\/p>\n\n\n\n<p>Third, the <code>merge_condition<\/code> results in three states: <code>MATCHED<\/code>, <code>NOT MATCHED<\/code>, and <code>NOT MATCHED BY SOURCE<\/code>.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>MATCHED<\/code>: these are the rows that match the merge condition. In the diagram, they are shown as blue. For the matching rows, you need to update the rows columns in the target table with values from the source table.<\/li><li><code>NOT MATCHED<\/code>: these are the rows from the source table that does not have any matching rows in the target table. In the diagram, they are shown as orange. In this case, you need to add the rows from the source table to the target table. Note that <code>NOT MATCHED<\/code> is also known as <code>NOT MATCHED BY TARGET<\/code>.<\/li><li><code>NOT MATCHED BY SOURCE<\/code>: these are the rows in the target table that does not match any rows in the source table. They are shown as green in the diagram. If you want to synchronize the target table with the data from the source table, then you will need to use this match condition to delete rows from the target table.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='sql-server-merge-statement-example'>SQL Server MERGE statement example <a href=\"#sql-server-merge-statement-example\" class=\"anchor\" id=\"sql-server-merge-statement-example\" title=\"Anchor for SQL Server &lt;code&gt;MERGE&lt;\/code&gt; statement example\">#<\/a><\/h2>\n\n\n\n<p>Suppose we have two table <code>sales.category<\/code> and <code>sales.category_staging<\/code> that store the sales by product category.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> sales.category (\n    category_id <span class=\"hljs-built_in\">INT<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n    category_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    amount <span class=\"hljs-built_in\">DECIMAL<\/span>(<span class=\"hljs-number\">10<\/span> , <span class=\"hljs-number\">2<\/span> )\n);\n\n<span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> sales.category(category_id, category_name, amount)\n<span class=\"hljs-keyword\">VALUES<\/span>(<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-string\">'Children Bicycles'<\/span>,<span class=\"hljs-number\">15000<\/span>),\n    (<span class=\"hljs-number\">2<\/span>,<span class=\"hljs-string\">'Comfort Bicycles'<\/span>,<span class=\"hljs-number\">25000<\/span>),\n    (<span class=\"hljs-number\">3<\/span>,<span class=\"hljs-string\">'Cruisers Bicycles'<\/span>,<span class=\"hljs-number\">13000<\/span>),\n    (<span class=\"hljs-number\">4<\/span>,<span class=\"hljs-string\">'Cyclocross Bicycles'<\/span>,<span class=\"hljs-number\">10000<\/span>);\n\n\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> sales.category_staging (\n    category_id <span class=\"hljs-built_in\">INT<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n    category_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    amount <span class=\"hljs-built_in\">DECIMAL<\/span>(<span class=\"hljs-number\">10<\/span> , <span class=\"hljs-number\">2<\/span> )\n);\n\n\n<span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> sales.category_staging(category_id, category_name, amount)\n<span class=\"hljs-keyword\">VALUES<\/span>(<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-string\">'Children Bicycles'<\/span>,<span class=\"hljs-number\">15000<\/span>),\n    (<span class=\"hljs-number\">3<\/span>,<span class=\"hljs-string\">'Cruisers Bicycles'<\/span>,<span class=\"hljs-number\">13000<\/span>),\n    (<span class=\"hljs-number\">4<\/span>,<span class=\"hljs-string\">'Cyclocross Bicycles'<\/span>,<span class=\"hljs-number\">20000<\/span>),\n    (<span class=\"hljs-number\">5<\/span>,<span class=\"hljs-string\">'Electric Bikes'<\/span>,<span class=\"hljs-number\">10000<\/span>),\n    (<span class=\"hljs-number\">6<\/span>,<span class=\"hljs-string\">'Mountain Bikes'<\/span>,<span class=\"hljs-number\">10000<\/span>);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To update data to the <code>sales.category<\/code> (target table) with the values from the <code>sales.category_staging<\/code> (source table), you use the following <code>MERGE<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">MERGE<\/span> sales.category t \n    <span class=\"hljs-keyword\">USING<\/span> sales.category_staging s\n<span class=\"hljs-keyword\">ON<\/span> (s.category_id = t.category_id)\n<span class=\"hljs-keyword\">WHEN<\/span> <span class=\"hljs-keyword\">MATCHED<\/span>\n    <span class=\"hljs-keyword\">THEN<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">SET<\/span> \n        t.category_name = s.category_name,\n        t.amount = s.amount\n<span class=\"hljs-keyword\">WHEN<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">MATCHED<\/span> <span class=\"hljs-keyword\">BY<\/span> TARGET \n    <span class=\"hljs-keyword\">THEN<\/span> <span class=\"hljs-keyword\">INSERT<\/span> (category_id, category_name, amount)\n         <span class=\"hljs-keyword\">VALUES<\/span> (s.category_id, s.category_name, s.amount)\n<span class=\"hljs-keyword\">WHEN<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">MATCHED<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-keyword\">SOURCE<\/span> \n    <span class=\"hljs-keyword\">THEN<\/span> <span class=\"hljs-keyword\">DELETE<\/span>;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"871\" height=\"354\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-MERGE-Example.png\" alt=\"SQL Server MERGE Example\" class=\"wp-image-728\" srcset=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-MERGE-Example.png 871w, https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-MERGE-Example-300x122.png 300w, https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-MERGE-Example-768x312.png 768w\" sizes=\"auto, (max-width: 871px) 100vw, 871px\" \/><\/figure>\n\n\n\n<p>In this example, we used the values in the <code>category_id<\/code> columns in both tables as the merge condition.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>First, the rows with id 1, 3, 4 from the <code>sales.category_staging<\/code> table matches with the rows from the target table, therefore, the <code>MERGE<\/code> statement updates the values in category name and amount columns in the <code>sales.category<\/code> table.<\/li><li>Second, the rows with id 5 and 6 from the <code>sales.category_staging<\/code> table do not exist in the <code>sales.category<\/code> table, so the <code>MERGE<\/code> statement inserts these rows into the target table.<\/li><li>Third, the row with id 2 from the <code>sales.category<\/code> table does not exist in the <code>sales.sales_staging<\/code> table, therefore, the <code>MERGE<\/code> statement deletes this row.<\/li><\/ul>\n\n\n\n<p>As a result of the merger, the data in the <code>sales.category<\/code> table is fully synchronized with the data in the&nbsp;<code>sales.category_staging<\/code> table.<\/p>\n\n\n\n<p>In this tutorial, you have learned how to use the SQL Server <code>MERGE<\/code> statement to make changes in a table based on matching values from another table.<\/p>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"724\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/\"\n\t\t\t\tdata-post-title=\"SQL Server MERGE\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"724\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/\"\n\t\t\t\tdata-post-title=\"SQL Server MERGE\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows you how to use the SQL Server MERGE statement to update data in a table based on values matched from another table.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":100,"menu_order":41,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-724","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL Server MERGE: The Essential Guide to MERGE Statement<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use the SQL Server MERGE statement to update data in a table based on values matched from another table.\" \/>\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.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server MERGE: The Essential Guide to MERGE Statement\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use the SQL Server MERGE statement to update data in a table based on values matched from another table.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Server Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-11T13:13:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-MERGE.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-merge\\\/\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-merge\\\/\",\"name\":\"SQL Server MERGE: The Essential Guide to MERGE Statement\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-merge\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-merge\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/SQL-Server-MERGE.png\",\"datePublished\":\"2018-07-31T02:32:50+00:00\",\"dateModified\":\"2020-04-11T13:13:17+00:00\",\"description\":\"This tutorial shows you how to use the SQL Server MERGE statement to update data in a table based on values matched from another table.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-merge\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-merge\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-merge\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/SQL-Server-MERGE.png\",\"contentUrl\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/SQL-Server-MERGE.png\",\"width\":659,\"height\":377,\"caption\":\"SQL Server MERGE\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-merge\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server Basics\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL Server MERGE\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\",\"name\":\"SQL Server Tutorial\",\"description\":\"The Practical SQL Server Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Server MERGE: The Essential Guide to MERGE Statement","description":"This tutorial shows you how to use the SQL Server MERGE statement to update data in a table based on values matched from another table.","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.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server MERGE: The Essential Guide to MERGE Statement","og_description":"This tutorial shows you how to use the SQL Server MERGE statement to update data in a table based on values matched from another table.","og_url":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/","og_site_name":"SQL Server Tutorial","article_modified_time":"2020-04-11T13:13:17+00:00","og_image":[{"url":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-MERGE.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/","url":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/","name":"SQL Server MERGE: The Essential Guide to MERGE Statement","isPartOf":{"@id":"https:\/\/www.sqlservertutorial.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-MERGE.png","datePublished":"2018-07-31T02:32:50+00:00","dateModified":"2020-04-11T13:13:17+00:00","description":"This tutorial shows you how to use the SQL Server MERGE statement to update data in a table based on values matched from another table.","breadcrumb":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/#primaryimage","url":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-MERGE.png","contentUrl":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-MERGE.png","width":659,"height":377,"caption":"SQL Server MERGE"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-merge\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlservertutorial.net\/"},{"@type":"ListItem","position":2,"name":"SQL Server Basics","item":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/"},{"@type":"ListItem","position":3,"name":"SQL Server MERGE"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlservertutorial.net\/#website","url":"https:\/\/www.sqlservertutorial.net\/","name":"SQL Server Tutorial","description":"The Practical SQL Server Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlservertutorial.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/comments?post=724"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/724\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/100"}],"wp:attachment":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/media?parent=724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}