{"id":89,"date":"2020-10-29T09:55:06","date_gmt":"2020-10-29T01:55:06","guid":{"rendered":"https:\/\/www.db2go.net\/?p=89"},"modified":"2020-10-29T09:55:06","modified_gmt":"2020-10-29T01:55:06","slug":"mysql%e4%b8%ad%e5%b8%b8%e7%94%a8%e7%9a%84%e4%b8%89%e7%a7%8d%e6%8f%92%e5%85%a5%e6%95%b0%e6%8d%ae%e7%9a%84%e8%af%ad%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/www.db2go.net\/?p=89","title":{"rendered":"MySQL\u4e2d\u5e38\u7528\u7684\u4e09\u79cd\u63d2\u5165\u6570\u636e\u7684\u8bed\u53e5"},"content":{"rendered":"<p>MySQL\u4e2d\u5e38\u7528\u7684\u4e09\u79cd\u63d2\u5165\u6570\u636e\u7684\u8bed\u53e5:<\/p>\n<ul>\n<li>insert into<\/li>\n<li>replace into<\/li>\n<li>insert ignore into<\/li>\n<\/ul>\n<ol>\n<li><code>insert into<\/code> \u8868\u793a\u63d2\u5165\u6570\u636e\uff0c\u6570\u636e\u5e93\u4f1a\u68c0\u67e5\u4e3b\u952e\uff08PrimaryKey\uff09\uff0c\u5982\u679c\u51fa\u73b0\u91cd\u590d\u5219\u62a5\u9519\u3002<\/p>\n<\/li>\n<li>\n<p><code>replace into<\/code> \u8868\u793a\u63d2\u5165\u66ff\u6362\u6570\u636e\uff0c\u9700\u6c42\u8868\u4e2d\u6709PrimaryKey\uff0c\u6216\u8005unique\u7d22\u5f15\u7684\u8bdd\uff0c\u5982\u679c\u6570\u636e\u5e93\u5df2\u7ecf\u5b58\u5728\u6570\u636e\uff0c\u5219\u7528\u65b0\u6570\u636e\u66ff\u6362\uff0c\u5982\u679c\u6ca1\u6709\u6570\u636e\u6548\u679c\u5219\u548cinsert into\u4e00\u6837\u3002\u53e6\u5916\uff0cREPLACE\u8bed\u53e5\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6570\uff0c\u6765\u6307\u793a\u53d7\u5f71\u54cd\u7684\u884c\u7684\u6570\u76ee\uff0c\u8be5\u6570\u662f\u88ab\u5220\u9664\u548c\u88ab\u63d2\u5165\u7684\u884c\u6570\u7684\u548c\u3002\u5982\u679c\u5bf9\u4e8e\u4e00\u4e2a\u5355\u884cREPLACE\u8be5\u6570\u4e3a1\uff0c\u5219\u4e00\u884c\u88ab\u63d2\u5165\uff0c\u540c\u65f6\u6ca1\u6709\u884c\u88ab\u5220\u9664\u3002\u5982\u679c\u8be5\u6570\u5927\u4e8e1\uff0c\u5219\u5728\u65b0\u884c\u88ab\u63d2\u5165\u524d\uff0c\u6709\u4e00\u4e2a\u6216\u591a\u4e2a\u65e7\u884c\u88ab\u5220\u9664\u3002\u5982\u679c\u8868\u5305\u542b\u591a\u4e2a\u552f\u4e00\u7d22\u5f15\uff0c\u5e76\u4e14\u65b0\u884c\u590d\u5236\u4e86\u5728\u4e0d\u540c\u7684\u552f\u4e00\u7d22\u5f15\u4e2d\u7684\u4e0d\u540c\u65e7\u884c\u7684\u503c\uff0c\u5219\u6709\u53ef\u80fd\u662f\u4e00\u4e2a\u5355\u4e00\u884c\u66ff\u6362\u4e86\u591a\u4e2a\u65e7\u884c\u3002<\/p>\n<\/li>\n<li>\n<p><code>insert ignore<\/code> \u8868\u793a\u5982\u679c\u4e2d\u5df2\u7ecf\u5b58\u5728\u76f8\u540c\u7684\u8bb0\u5f55\uff0c\u5219\u5ffd\u7565\u5f53\u524d\u65b0\u6570\u636e\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-sql line-numbers\">create table test_tab(\n  id int not null primary key,\n  name varchar(50),\n  age int\n);\n\ninsert into test_tab(id,name,age)values(1,\"bb\",13);\nselect * from test_tab;\ninsert ignore into testtb(id,name,age)values(1,\"aa\",13);\nselect * from test_tab;\/\/\u4ecd\u662f1\uff0c\u201cbb\u201d,13\uff0c\u56e0\u4e3aid\u662f\u4e3b\u952e\uff0c\u51fa\u73b0\u4e3b\u952e\u91cd\u590d\u4f46\u4f7f\u7528\u4e86ignore\u5219\u9519\u8bef\u88ab\u5ffd\u7565\nreplace into test_tab(id,name,age)values(1,\"aa\",12);\nselect * from test_tab; \/\/\u6570\u636e\u53d8\u4e3a1,\"aa\",12\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>MySQL\u4e2d\u5e38\u7528\u7684\u4e09\u79cd\u63d2\u5165\u6570\u636e\u7684\u8bed\u53e5: insert into replace into insert ign&hellip;<\/p>\n <a href=\"https:\/\/www.db2go.net\/?p=89\" title=\"MySQL\u4e2d\u5e38\u7528\u7684\u4e09\u79cd\u63d2\u5165\u6570\u636e\u7684\u8bed\u53e5\" class=\"entry-more-link\"><span>Read More<\/span> <span class=\"screen-reader-text\">MySQL\u4e2d\u5e38\u7528\u7684\u4e09\u79cd\u63d2\u5165\u6570\u636e\u7684\u8bed\u53e5<\/span><\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[5],"tags":[],"class_list":["entry","author-suredandan","post-89","post","type-post","status-publish","format-standard","category-mysql"],"views":1963,"_links":{"self":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=89"}],"version-history":[{"count":1,"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":90,"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions\/90"}],"wp:attachment":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}