{"id":186126,"date":"2024-11-11T03:19:30","date_gmt":"2024-11-10T19:19:30","guid":{"rendered":"https:\/\/server.hk\/cnblog\/186126\/"},"modified":"2024-11-11T03:19:31","modified_gmt":"2024-11-10T19:19:31","slug":"%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%e6%af%94%e8%bc%83%e6%8c%87%e5%8d%97%ef%bc%9a%e4%ba%86%e8%a7%a3%e5%a6%82%e4%bd%95%e6%af%94%e8%bc%83%e5%85%a9%e5%bc%b5%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%ef%bc%88","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/186126\/","title":{"rendered":"\u6578\u64da\u5eab\u8868\u6bd4\u8f03\u6307\u5357\uff1a\u4e86\u89e3\u5982\u4f55\u6bd4\u8f03\u5169\u5f35\u6578\u64da\u5eab\u8868\uff08\u5982\u4f55\u6bd4\u8f03\u6578\u64da\u5eab\u7576\u4e2d\u7684\u5169\u5f35\u8868\uff09"},"content":{"rendered":"<h1 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%e6%af%94%e8%bc%83%e6%8c%87%e5%8d%97%ef%bc%9a%e4%ba%86%e8%a7%a3%e5%a6%82%e4%bd%95%e6%af%94%e8%bc%83%e5%85%a9%e5%bc%b5%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8-sRcuSbtBLT\">\u6578\u64da\u5eab\u8868\u6bd4\u8f03\u6307\u5357\uff1a\u4e86\u89e3\u5982\u4f55\u6bd4\u8f03\u5169\u5f35\u6578\u64da\u5eab\u8868<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0c\u8868\u7684\u6bd4\u8f03\u662f\u4e00\u9805\u91cd\u8981\u7684\u4efb\u52d9\u3002\u7121\u8ad6\u662f\u70ba\u4e86\u6578\u64da\u9077\u79fb\u3001\u6578\u64da\u6574\u5408\uff0c\u9084\u662f\u70ba\u4e86\u78ba\u4fdd\u6578\u64da\u7684\u4e00\u81f4\u6027\uff0c\u4e86\u89e3\u5982\u4f55\u6709\u6548\u5730\u6bd4\u8f03\u5169\u5f35\u6578\u64da\u5eab\u8868\u90fd\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5e7e\u7a2e\u5e38\u898b\u7684\u65b9\u6cd5\u548c\u5de5\u5177\uff0c\u5e6b\u52a9\u60a8\u5728\u6578\u64da\u5eab\u4e2d\u6bd4\u8f03\u5169\u5f35\u8868\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e6%af%94%e8%bc%83%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%ef%bc%9f-sRcuSbtBLT\">\u70ba\u4ec0\u9ebc\u9700\u8981\u6bd4\u8f03\u6578\u64da\u5eab\u8868\uff1f<\/h2>\n<p>\u6bd4\u8f03\u6578\u64da\u5eab\u8868\u7684\u539f\u56e0\u6709\u5f88\u591a\uff0c\u4e3b\u8981\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u4e00\u81f4\u6027\uff1a<\/strong>\u78ba\u4fdd\u5169\u5f35\u8868\u4e2d\u7684\u6578\u64da\u4e00\u81f4\uff0c\u7279\u5225\u662f\u5728\u6578\u64da\u9077\u79fb\u6216\u540c\u6b65\u904e\u7a0b\u4e2d\u3002<\/li>\n<li><strong>\u6578\u64da\u5b8c\u6574\u6027\uff1a<\/strong>\u6aa2\u67e5\u662f\u5426\u6709\u907a\u6f0f\u6216\u91cd\u8907\u7684\u6578\u64da\u3002<\/li>\n<li><strong>\u6027\u80fd\u512a\u5316\uff1a<\/strong>\u901a\u904e\u6bd4\u8f03\u8868\u7d50\u69cb\uff0c\u627e\u51fa\u5197\u9918\u7684\u6578\u64da\u6216\u4e0d\u5fc5\u8981\u7684\u7d22\u5f15\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%af%94%e8%bc%83%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%96%b9%e6%b3%95-sRcuSbtBLT\">\u6bd4\u8f03\u6578\u64da\u5eab\u8868\u7684\u57fa\u672c\u65b9\u6cd5<\/h2>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8sql%e6%9f%a5%e8%a9%a2-sRcuSbtBLT\">1. \u4f7f\u7528SQL\u67e5\u8a62<\/h3>\n<p>\u6700\u57fa\u672c\u7684\u6bd4\u8f03\u65b9\u6cd5\u662f\u4f7f\u7528SQL\u67e5\u8a62\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528JOIN\u8a9e\u53e5\u4f86\u6bd4\u8f03\u5169\u5f35\u8868\u4e2d\u7684\u6578\u64da\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u6709\u5169\u5f35\u8868\uff1a<code>table_a<\/code>\u548c<code>table_b<\/code>\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8a62\u4f86\u627e\u51fa\u4e0d\u4e00\u81f4\u7684\u6578\u64da\uff1a<\/p>\n<pre><code>SELECT a.*\nFROM table_a a\nLEFT JOIN table_b b ON a.id = b.id\nWHERE b.id IS NULL;<\/code><\/pre>\n<p>\u9019\u500b\u67e5\u8a62\u5c07\u8fd4\u56de\u5728<code>table_a<\/code>\u4e2d\u5b58\u5728\u4f46\u5728<code>table_b<\/code>\u4e2d\u4e0d\u5b58\u5728\u7684\u6240\u6709\u8a18\u9304\u3002<\/p>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e7%ae%a1%e7%90%86%e5%b7%a5%e5%85%b7-sRcuSbtBLT\">2. \u4f7f\u7528\u6578\u64da\u5eab\u7ba1\u7406\u5de5\u5177<\/h3>\n<p>\u8a31\u591a\u6578\u64da\u5eab\u7ba1\u7406\u5de5\u5177\u63d0\u4f9b\u4e86\u53ef\u8996\u5316\u7684\u8868\u6bd4\u8f03\u529f\u80fd\u3002\u4f8b\u5982\uff0c<strong>MySQL Workbench<\/strong>\u548c<strong>SQL Server Management Studio<\/strong>\u90fd\u53ef\u4ee5\u5e6b\u52a9\u7528\u6236\u8f15\u9b06\u6bd4\u8f03\u8868\u7d50\u69cb\u548c\u6578\u64da\u3002\u9019\u4e9b\u5de5\u5177\u901a\u5e38\u63d0\u4f9b\u76f4\u89c0\u7684\u754c\u9762\uff0c\u8b93\u7528\u6236\u80fd\u5920\u5feb\u901f\u8b58\u5225\u5dee\u7570\u3002<\/p>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8%e5%b0%88%e7%94%a8%e7%9a%84%e6%af%94%e8%bc%83%e5%b7%a5%e5%85%b7-sRcuSbtBLT\">3. \u4f7f\u7528\u5c08\u7528\u7684\u6bd4\u8f03\u5de5\u5177<\/h3>\n<p>\u9664\u4e86\u6578\u64da\u5eab\u7ba1\u7406\u5de5\u5177\u5916\uff0c\u9084\u6709\u4e00\u4e9b\u5c08\u9580\u7684\u6bd4\u8f03\u5de5\u5177\u53ef\u4ee5\u7528\u4f86\u6bd4\u8f03\u6578\u64da\u5eab\u8868\u3002\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li><strong>Redgate SQL Compare\uff1a<\/strong>\u9019\u662f\u4e00\u6b3e\u529f\u80fd\u5f37\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u6bd4\u8f03\u548c\u540c\u6b65SQL Server\u6578\u64da\u5eab\u7684\u7d50\u69cb\u548c\u6578\u64da\u3002<\/li>\n<li><strong>dbForge Data Compare\uff1a<\/strong>\u9019\u662f\u4e00\u6b3e\u91dd\u5c0d\u591a\u7a2e\u6578\u64da\u5eab\u7684\u6bd4\u8f03\u5de5\u5177\uff0c\u652f\u6301MySQL\u3001PostgreSQL\u7b49\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%af%94%e8%bc%83%e8%a1%a8%e7%b5%90%e6%a7%8b-sRcuSbtBLT\">\u6bd4\u8f03\u8868\u7d50\u69cb<\/h2>\n<p>\u9664\u4e86\u6bd4\u8f03\u8868\u4e2d\u7684\u6578\u64da\u5916\uff0c\u8868\u7684\u7d50\u69cb\u4e5f\u9700\u8981\u9032\u884c\u6bd4\u8f03\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0bSQL\u67e5\u8a62\u4f86\u7372\u53d6\u8868\u7684\u7d50\u69cb\u4fe1\u606f\uff1a<\/p>\n<pre><code>SHOW CREATE TABLE table_a;<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a<code>table_a<\/code>\u7684\u5275\u5efa\u8a9e\u53e5\uff0c\u60a8\u53ef\u4ee5\u5c07\u5176\u8207<code>table_b<\/code>\u7684\u5275\u5efa\u8a9e\u53e5\u9032\u884c\u6bd4\u8f03\uff0c\u4ee5\u78ba\u5b9a\u5169\u8005\u4e4b\u9593\u7684\u5dee\u7570\u3002<\/p>\n<h2 id=\"%e8%87%aa%e5%8b%95%e5%8c%96%e6%af%94%e8%bc%83%e9%81%8e%e7%a8%8b-sRcuSbtBLT\">\u81ea\u52d5\u5316\u6bd4\u8f03\u904e\u7a0b<\/h2>\n<p>\u5c0d\u65bc\u5927\u578b\u6578\u64da\u5eab\uff0c\u624b\u52d5\u6bd4\u8f03\u53ef\u80fd\u6703\u975e\u5e38\u7e41\u7463\u3002\u60a8\u53ef\u4ee5\u8003\u616e\u7de8\u5beb\u8173\u672c\u4f86\u81ea\u52d5\u5316\u9019\u4e00\u904e\u7a0b\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Python\u7684<code>pandas<\/code>\u5eab\u53ef\u4ee5\u8f15\u9b06\u5730\u8b80\u53d6\u6578\u64da\u4e26\u9032\u884c\u6bd4\u8f03\uff1a<\/p>\n<pre><code>import pandas as pd\n\n# \u8b80\u53d6\u6578\u64da\ntable_a = pd.read_sql('SELECT * FROM table_a', connection)\ntable_b = pd.read_sql('SELECT * FROM table_b', connection)\n\n# \u6bd4\u8f03\u6578\u64da\ncomparison = table_a.compare(table_b)\nprint(comparison)<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-sRcuSbtBLT\">\u7d50\u8ad6<\/h2>\n<p>\u6bd4\u8f03\u6578\u64da\u5eab\u8868\u662f\u4e00\u9805\u91cd\u8981\u7684\u4efb\u52d9\uff0c\u7121\u8ad6\u662f\u70ba\u4e86\u6578\u64da\u4e00\u81f4\u6027\u3001\u5b8c\u6574\u6027\u9084\u662f\u6027\u80fd\u512a\u5316\u3002\u901a\u904e\u4f7f\u7528SQL\u67e5\u8a62\u3001\u6578\u64da\u5eab\u7ba1\u7406\u5de5\u5177\u6216\u5c08\u7528\u7684\u6bd4\u8f03\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u6bd4\u8f03\u5169\u5f35\u8868\u7684\u6578\u64da\u548c\u7d50\u69cb\u3002\u96a8\u8457\u6578\u64da\u91cf\u7684\u589e\u9577\uff0c\u81ea\u52d5\u5316\u6bd4\u8f03\u904e\u7a0b\u5c07\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\uff0c\u9019\u6a23\u53ef\u4ee5\u7bc0\u7701\u6642\u9593\u4e26\u63d0\u9ad8\u6e96\u78ba\u6027\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u6258\u7ba1\u60a8\u7684\u6578\u64da\u5eab\u3002\u7121\u8ad6\u662f\u9700\u8981\u9ad8\u6027\u80fd\u7684<a href=\"https:\/\/server.hk\">\u4e91\u4f3a\u670d\u5668<\/a>\u9084\u662f\u7a69\u5b9a\u7684<a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\uff0cServer.HK\u90fd\u80fd\u63d0\u4f9b\u6eff\u8db3\u60a8\u9700\u6c42\u7684\u670d\u52d9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u6709\u6548\u6bd4\u8f03\u5169\u5f35\u6578\u64da\u5eab\u8868\uff0c\u638c\u63e1\u6280\u5de7\u8207\u5de5\u5177\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u8207\u5206\u6790\u80fd\u529b\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-186126","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/186126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=186126"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/186126\/revisions"}],"predecessor-version":[{"id":186127,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/186126\/revisions\/186127"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=186126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=186126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=186126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}