{"id":4466,"date":"2018-10-31T08:39:38","date_gmt":"2018-10-31T08:39:38","guid":{"rendered":"https:\/\/dbtut.com\/?p=4466"},"modified":"2018-11-28T07:34:55","modified_gmt":"2018-11-28T07:34:55","slug":"tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql","status":"publish","type":"post","link":"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/","title":{"rendered":"Tips when using &#8216;replace into&#8217; and &#8216;insert &#8230; on duplicate key update&#8230;&#8217; in MySQL"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>Sometimes when we want to insert rows into a table which contains duplicate keys, then we consider using &#8216;replace into&#8217; or &#8216;insert into &#8230; on duplicate key update &#8230;&#8217;. In my recent work, i found that there were some traps when using them, and this article is to show what will happen and why.<\/p>\n<h3><\/h3>\n<h3>1) replace into<\/h3>\n<pre class=\"lang:default decode:true \">CREATE TABLE `t1` (\r\n\r\n\u00a0 `a` int(11) NOT NULL AUTO_INCREMENT,\r\n\r\n\u00a0 `b` int(11) DEFAULT NULL,\r\n\r\n\u00a0 `c` int(11) DEFAULT NULL,\r\n\r\n\u00a0 PRIMARY KEY (`a`),\r\n\r\n\u00a0 UNIQUE KEY `uniq_b` (`b`)\r\n\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Replace a duplicate row:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">mysql&gt; select * from t1;\u00a0\r\n\r\n+---+------+------+\r\n\r\n| a | b\u00a0 \u00a0 | c\u00a0 \u00a0 |\r\n\r\n+---+------+------+\r\n\r\n| 1 |\u00a0 \u00a0 1 |\u00a0 \u00a0 2 |\r\n\r\n| 2 |\u00a0 \u00a0 2 | NULL |\r\n\r\n+---+------+------+<\/pre>\n<pre class=\"lang:default decode:true\">mysql&gt; replace into t1(b,c) values (1,9);\u00a0\r\n\r\nQuery OK, 2 rows affected (0.07 sec)<\/pre>\n<pre class=\"lang:default decode:true \">mysql&gt; select * from t1;\r\n\r\n+---+------+------+\r\n\r\n| a | b\u00a0 \u00a0 | c\u00a0 \u00a0 |\r\n\r\n+---+------+------+\r\n\r\n| 2 |\u00a0 \u00a0 2 | NULL |\r\n\r\n| 3 |\u00a0 \u00a0 1 |\u00a0 \u00a0 9 |\r\n\r\n+---+------+------+<\/pre>\n<p>&nbsp;<\/p>\n<p>After we used &#8216;replace into &#8230;&#8217; on the unique key, the (1,1,2) was deleted and a new row (3,1,9) was\u00a0inserted, it&#8217;s not just replaced values at the (1,1,2) row because the column &#8216;a&#8217; used the\u00a0AUTO_INCREMENT value &#8216;3&#8217;.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Column name must be specified:<\/strong><\/p>\n<p>If you didn&#8217;t specify the column name, for example:<\/p>\n<pre class=\"lang:default decode:true\">mysql&gt; select * from t1;\r\n\r\n+---+------+------+\r\n\r\n| a | b\u00a0 \u00a0 | c\u00a0 \u00a0 |\r\n\r\n+---+------+------+\r\n\r\n| 1 |\u00a0 \u00a0 1 |\u00a0 \u00a0 2 |\r\n\r\n| 2 |\u00a0 \u00a0 2 | NULL |\r\n\r\n+---+------+------+<\/pre>\n<pre class=\"lang:default decode:true\">mysql&gt; replace into t1(b) values (1);\r\n\r\nQuery OK, 2 rows affected (0.06 sec)<\/pre>\n<pre class=\"lang:default decode:true \">mysql&gt; select * from t1;\r\n\r\n+---+------+------+\r\n\r\n| a | b\u00a0 \u00a0 | c\u00a0 \u00a0 |\r\n\r\n+---+------+------+\r\n\r\n| 2 |\u00a0 \u00a0 2 | NULL |\r\n\r\n| 3 |\u00a0 \u00a0 1 | NULL |\r\n\r\n+---+------+------+<\/pre>\n<p>&nbsp;<\/p>\n<p>Column &#8216;a&#8217; and &#8216;c&#8217; have been changed into &#8216;3&#8217; and &#8216;null&#8217;, so when using &#8216;replace into&#8217;, it will delete the duplicate row and insert a new row\u00a0<b>with the default value<\/b>.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Replace a\u00a0duplicate primary key and a duplicate unique key at the same time:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">mysql&gt; select * from t1;\r\n\r\n+---+------+------+\r\n\r\n| a | b\u00a0 \u00a0 | c\u00a0 \u00a0 |\r\n\r\n+---+------+------+\r\n\r\n| 2 |\u00a0 \u00a0 2 |\u00a0 \u00a0 2 |\r\n\r\n| 3 |\u00a0 \u00a0 1 |\u00a0 \u00a0 2 |\r\n\r\n+---+------+------+<\/pre>\n<pre class=\"lang:default decode:true\">mysql&gt; replace into t1(a,b,c) values (2,1,9);\r\n\r\nQuery OK,\u00a03 rows affected\u00a0(0.10 sec)<\/pre>\n<pre class=\"lang:default decode:true \">mysql&gt; select * from t1;\r\n\r\n+---+------+------+\r\n\r\n| a | b\u00a0 \u00a0 | c\u00a0 \u00a0 |\r\n\r\n+---+------+------+\r\n\r\n| 2 |\u00a0 \u00a0 1 |\u00a0 \u00a0 9 |\r\n\r\n+---+------+------+<\/pre>\n<p>&nbsp;<\/p>\n<p>After &#8216;replace into &#8230;&#8217;, it shows &#8216;<b>3 rows affected\u00a0<\/b>&#8216;, two rows have been deleted and just one row is inserted into t1.<\/p>\n<p>As\u00a0mentioned before, &#8216;replace into ..&#8217; will delete the duplicate rows before inserting, so when the &#8216;replace into t1(a,b,c) values (2,1,9);&#8217; is executing, it checks the primary key first, it&#8217;s duplicated, so the (2,2,2) is deleted, then the column &#8216;b&#8217; is also duplicated, so the (3,1,2) is deleted, after that, no duplicate key exists, then insert a new row (2,1,9).<\/p>\n<h3><\/h3>\n<h3>2) Insert into &#8230; on duplicate key update &#8230;<\/h3>\n<p>Using the same table t1 for testing:<\/p>\n<p><strong>Insert a duplicate primary key row:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">mysql&gt; select * from t1;\u00a0\r\n\r\n+---+------+------+\r\n\r\n| a | b\u00a0 \u00a0 | c\u00a0 \u00a0 |\r\n\r\n+---+------+------+\r\n\r\n| 1 |\u00a0 \u00a0 1 |\u00a0 \u00a0 2 |\r\n\r\n| 2 |\u00a0 \u00a0 2 | NULL |\r\n\r\n+---+------+------+<\/pre>\n<pre class=\"lang:default decode:true\">mysql&gt; insert into t1(a,b,c) values (2,3,4) on duplicate key update c=4;\r\n\r\nQuery OK, 2 rows affected (0.02 sec)<\/pre>\n<pre class=\"lang:default decode:true \">mysql&gt; select * from t1;\r\n\r\n+---+------+------+\r\n\r\n| a | b\u00a0 \u00a0 | c\u00a0 \u00a0 |\r\n\r\n+---+------+------+\r\n\r\n| 1 |\u00a0 \u00a0 1 |\u00a0 \u00a0 2 |\r\n\r\n| 2 |\u00a0 \u00a0 2 |\u00a0 \u00a0 4 |\r\n\r\n+---+------+------+<\/pre>\n<p>&nbsp;<\/p>\n<p>The &#8216;insert &#8230; on duplicate key update&#8230;&#8217; just checked the primary key, and after found the primary key &#8216;a&#8217; had a duplicate value &#8216;2&#8217;, then it updated the column &#8216;c&#8217; to new value &#8216;4&#8217;, and ignored the column &#8216;b&#8217; which was also duplicate. So we got the new line (2,2,4) instead of (2,3,4).<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Insert on a duplicate key row:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">mysql&gt; select * from t1;\r\n\r\n+---+------+------+\r\n\r\n| a | b\u00a0 \u00a0 | c\u00a0 \u00a0 |\r\n\r\n+---+------+------+\r\n\r\n| 1 |\u00a0 \u00a0 1 |\u00a0 \u00a0 2 |\r\n\r\n| 2 |\u00a0 \u00a0 2 |\u00a0 \u00a0 4 |\r\n\r\n+---+------+------+<\/pre>\n<pre class=\"lang:default decode:true\">mysql&gt; insert into t1(b,c) values (1,5) on duplicate key update c=5;\r\n\r\nQuery OK, 2 rows affected (0.20 sec)<\/pre>\n<pre class=\"lang:default decode:true \">mysql&gt; select * from t1;\r\n\r\n+---+------+------+\r\n\r\n| a | b\u00a0 \u00a0 | c\u00a0 \u00a0 |\r\n\r\n+---+------+------+\r\n\r\n| 1 |\u00a0 \u00a0 1 |\u00a0 \u00a0 5 |\r\n\r\n| 2 |\u00a0 \u00a0 2 |\u00a0 \u00a0 4 |\r\n\r\n+---+------+------+<\/pre>\n<p>&nbsp;<\/p>\n<p>This is different with &#8216;replace into ..&#8217;, it just updates the value on the duplicate row, with no deletion.<\/p>\n<p>In a word, before using &#8216;replace into&#8230;&#8217; and &#8216;insert into &#8230; on duplicate key update &#8230;&#8217;, you must know what they actually do, otherwise you will get unexpected results.<\/p>\n\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_4466\" class=\"pvc_stats all  \" data-element-id=\"4466\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/dbtut.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Sometimes when we want to insert rows into a table which contains duplicate keys, then we consider using &#8216;replace into&#8217; or &#8216;insert into &#8230; on duplicate key update &#8230;&#8217;. In my recent work, i found that there were some traps when using them, and this article is to show what will happen and why. &hellip;<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_4466\" class=\"pvc_stats all  \" data-element-id=\"4466\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/dbtut.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":50,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[7],"tags":[1301,1550],"class_list":["post-4466","post","type-post","status-publish","format-standard","","category-mysql","tag-mysql","tag-sql"],"aioseo_notices":[],"a3_pvc":{"activated":true,"total_views":2022,"today_views":0},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Tips when using &#039;replace into&#039; and &#039;insert ... on duplicate key update...&#039; in MySQL - Database Tutorials<\/title>\n<meta name=\"description\" content=\"Tips when using &#039;replace into&#039; and &#039;insert ... on duplicate key update...&#039; in MySQL\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tips when using &#039;replace into&#039; and &#039;insert ... on duplicate key update...&#039; in MySQL - Database Tutorials\" \/>\n<meta property=\"og:description\" content=\"Tips when using &#039;replace into&#039; and &#039;insert ... on duplicate key update...&#039; in MySQL\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/\" \/>\n<meta property=\"og:site_name\" content=\"Database Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2018-10-31T08:39:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-11-28T07:34:55+00:00\" \/>\n<meta name=\"author\" content=\"Shuo Wang\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shuo Wang\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/\"},\"author\":{\"name\":\"Shuo Wang\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/83d7028b846c78bfd03244ec6cd04289\"},\"headline\":\"Tips when using &#8216;replace into&#8217; and &#8216;insert &#8230; on duplicate key update&#8230;&#8217; in MySQL\",\"datePublished\":\"2018-10-31T08:39:38+00:00\",\"dateModified\":\"2018-11-28T07:34:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/\"},\"wordCount\":393,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/dbtut.com\/#organization\"},\"keywords\":[\"MySQL\",\"sql\"],\"articleSection\":[\"MySQL-MariaDB\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/\",\"url\":\"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/\",\"name\":\"Tips when using 'replace into' and 'insert ... on duplicate key update...' in MySQL - Database Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/dbtut.com\/#website\"},\"datePublished\":\"2018-10-31T08:39:38+00:00\",\"dateModified\":\"2018-11-28T07:34:55+00:00\",\"description\":\"Tips when using 'replace into' and 'insert ... on duplicate key update...' in MySQL\",\"breadcrumb\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dbtut.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tips when using &#8216;replace into&#8217; and &#8216;insert &#8230; on duplicate key update&#8230;&#8217; in MySQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dbtut.com\/#website\",\"url\":\"https:\/\/dbtut.com\/\",\"name\":\"Database Tutorials\",\"description\":\"MSSQL, Oracle, PostgreSQL, MySQL, MariaDB, DB2, Sybase, Teradata, Big Data, NOSQL, MongoDB, Couchbase, Cassandra, Windows, Linux\",\"publisher\":{\"@id\":\"https:\/\/dbtut.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dbtut.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/dbtut.com\/#organization\",\"name\":\"dbtut\",\"url\":\"https:\/\/dbtut.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg\",\"contentUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg\",\"width\":223,\"height\":36,\"caption\":\"dbtut\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/83d7028b846c78bfd03244ec6cd04289\",\"name\":\"Shuo Wang\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/da30aa3d0157ae5f1f853927f56b868cfb1d801888eb954768c471e5d41cdd87?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/da30aa3d0157ae5f1f853927f56b868cfb1d801888eb954768c471e5d41cdd87?s=96&d=mm&r=g\",\"caption\":\"Shuo Wang\"},\"url\":\"https:\/\/dbtut.com\/index.php\/author\/shuowang\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tips when using 'replace into' and 'insert ... on duplicate key update...' in MySQL - Database Tutorials","description":"Tips when using 'replace into' and 'insert ... on duplicate key update...' in MySQL","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:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/","og_locale":"en_US","og_type":"article","og_title":"Tips when using 'replace into' and 'insert ... on duplicate key update...' in MySQL - Database Tutorials","og_description":"Tips when using 'replace into' and 'insert ... on duplicate key update...' in MySQL","og_url":"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/","og_site_name":"Database Tutorials","article_published_time":"2018-10-31T08:39:38+00:00","article_modified_time":"2018-11-28T07:34:55+00:00","author":"Shuo Wang","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Shuo Wang","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/#article","isPartOf":{"@id":"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/"},"author":{"name":"Shuo Wang","@id":"https:\/\/dbtut.com\/#\/schema\/person\/83d7028b846c78bfd03244ec6cd04289"},"headline":"Tips when using &#8216;replace into&#8217; and &#8216;insert &#8230; on duplicate key update&#8230;&#8217; in MySQL","datePublished":"2018-10-31T08:39:38+00:00","dateModified":"2018-11-28T07:34:55+00:00","mainEntityOfPage":{"@id":"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/"},"wordCount":393,"commentCount":0,"publisher":{"@id":"https:\/\/dbtut.com\/#organization"},"keywords":["MySQL","sql"],"articleSection":["MySQL-MariaDB"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/","url":"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/","name":"Tips when using 'replace into' and 'insert ... on duplicate key update...' in MySQL - Database Tutorials","isPartOf":{"@id":"https:\/\/dbtut.com\/#website"},"datePublished":"2018-10-31T08:39:38+00:00","dateModified":"2018-11-28T07:34:55+00:00","description":"Tips when using 'replace into' and 'insert ... on duplicate key update...' in MySQL","breadcrumb":{"@id":"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/dbtut.com\/index.php\/2018\/10\/31\/tips-when-using-replace-into-and-insert-on-duplicate-key-update-in-mysql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dbtut.com\/"},{"@type":"ListItem","position":2,"name":"Tips when using &#8216;replace into&#8217; and &#8216;insert &#8230; on duplicate key update&#8230;&#8217; in MySQL"}]},{"@type":"WebSite","@id":"https:\/\/dbtut.com\/#website","url":"https:\/\/dbtut.com\/","name":"Database Tutorials","description":"MSSQL, Oracle, PostgreSQL, MySQL, MariaDB, DB2, Sybase, Teradata, Big Data, NOSQL, MongoDB, Couchbase, Cassandra, Windows, Linux","publisher":{"@id":"https:\/\/dbtut.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dbtut.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/dbtut.com\/#organization","name":"dbtut","url":"https:\/\/dbtut.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/#\/schema\/logo\/image\/","url":"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg","contentUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg","width":223,"height":36,"caption":"dbtut"},"image":{"@id":"https:\/\/dbtut.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/dbtut.com\/#\/schema\/person\/83d7028b846c78bfd03244ec6cd04289","name":"Shuo Wang","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/da30aa3d0157ae5f1f853927f56b868cfb1d801888eb954768c471e5d41cdd87?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/da30aa3d0157ae5f1f853927f56b868cfb1d801888eb954768c471e5d41cdd87?s=96&d=mm&r=g","caption":"Shuo Wang"},"url":"https:\/\/dbtut.com\/index.php\/author\/shuowang\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts\/4466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/users\/50"}],"replies":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/comments?post=4466"}],"version-history":[{"count":0,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts\/4466\/revisions"}],"wp:attachment":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/media?parent=4466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/categories?post=4466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/tags?post=4466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}