{"id":163707,"date":"2024-11-05T01:45:25","date_gmt":"2024-11-04T17:45:25","guid":{"rendered":"https:\/\/server.hk\/cnblog\/163707\/"},"modified":"2024-11-05T01:45:26","modified_gmt":"2024-11-04T17:45:26","slug":"%e8%a7%a3%e6%b1%basql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%8d%a1%e9%a0%93%e5%95%8f%e9%a1%8c%e7%9a%84%e6%9c%89%e6%95%88%e6%96%b9%e6%b3%95-sql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%be%88%e5%8d%a1","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/163707\/","title":{"rendered":"\u89e3\u6c7aSQL\u6578\u64da\u5eab\u5361\u9813\u554f\u984c\u7684\u6709\u6548\u65b9\u6cd5 (sql\u6578\u64da\u5eab\u5f88\u5361)"},"content":{"rendered":"<h1 id=\"%e8%a7%a3%e6%b1%basql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%8d%a1%e9%a0%93%e5%95%8f%e9%a1%8c%e7%9a%84%e6%9c%89%e6%95%88%e6%96%b9%e6%b3%95-CzWJAUOqaO\">\u89e3\u6c7aSQL\u6578\u64da\u5eab\u5361\u9813\u554f\u984c\u7684\u6709\u6548\u65b9\u6cd5<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u4e16\u754c\u4e2d\uff0cSQL\u6578\u64da\u5eab\u7684\u6027\u80fd\u5c0d\u65bc\u61c9\u7528\u7a0b\u5e8f\u7684\u6574\u9ad4\u6548\u7387\u81f3\u95dc\u91cd\u8981\u3002\u7136\u800c\uff0c\u96a8\u8457\u6578\u64da\u91cf\u7684\u589e\u9577\u548c\u7528\u6236\u8acb\u6c42\u7684\u589e\u52a0\uff0c\u8a31\u591a\u4f01\u696d\u9762\u81e8\u8457SQL\u6578\u64da\u5eab\u5361\u9813\u7684\u554f\u984c\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u4e00\u4e9b\u6709\u6548\u7684\u65b9\u6cd5\u4f86\u89e3\u6c7a\u9019\u4e9b\u6027\u80fd\u74f6\u9838\u3002<\/p>\n<h2 id=\"1-%e5%84%aa%e5%8c%96%e6%9f%a5%e8%a9%a2-CzWJAUOqaO\">1. \u512a\u5316\u67e5\u8a62<\/h2>\n<p>\u67e5\u8a62\u6027\u80fd\u662f\u5f71\u97ffSQL\u6578\u64da\u5eab\u901f\u5ea6\u7684\u4e3b\u8981\u56e0\u7d20\u4e4b\u4e00\u3002\u512a\u5316\u67e5\u8a62\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u97ff\u61c9\u901f\u5ea6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u512a\u5316\u67e5\u8a62\u7684\u5efa\u8b70\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u7d22\u5f15\uff1a<\/strong>\u7d22\u5f15\u53ef\u4ee5\u52a0\u901f\u67e5\u8a62\u7684\u57f7\u884c\u3002\u78ba\u4fdd\u5728\u7d93\u5e38\u67e5\u8a62\u7684\u5217\u4e0a\u5275\u5efa\u7d22\u5f15\uff0c\u7279\u5225\u662f\u4e3b\u9375\u548c\u5916\u9375\u3002<\/li>\n<li><strong>\u907f\u514dSELECT *\uff1a<\/strong>\u4f7f\u7528\u5177\u9ad4\u7684\u5217\u540d\u800c\u4e0d\u662fSELECT *\uff0c\u9019\u6a23\u53ef\u4ee5\u6e1b\u5c11\u4e0d\u5fc5\u8981\u7684\u6578\u64da\u50b3\u8f38\u3002<\/li>\n<li><strong>\u4f7f\u7528JOIN\u800c\u975e\u5b50\u67e5\u8a62\uff1a<\/strong>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u4f7f\u7528JOIN\u53ef\u4ee5\u6bd4\u5b50\u67e5\u8a62\u66f4\u9ad8\u6548\u3002<\/li>\n<\/ul>\n<pre><code>SELECT column1, column2 FROM table1 JOIN table2 ON table1.id = table2.id;<\/code><\/pre>\n<h2 id=\"2-%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a8%ad%e8%a8%88-CzWJAUOqaO\">2. \u6578\u64da\u5eab\u8a2d\u8a08<\/h2>\n<p>\u826f\u597d\u7684\u6578\u64da\u5eab\u8a2d\u8a08\u53ef\u4ee5\u6e1b\u5c11\u5361\u9813\u7684\u767c\u751f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u8a2d\u8a08\u4e0a\u7684\u8003\u91cf\uff1a<\/p>\n<ul>\n<li><strong>\u6b63\u898f\u5316\uff1a<\/strong>\u901a\u904e\u6b63\u898f\u5316\u4f86\u6d88\u9664\u6578\u64da\u5197\u9918\uff0c\u9019\u6a23\u53ef\u4ee5\u63d0\u9ad8\u6578\u64da\u7684\u4e00\u81f4\u6027\u548c\u67e5\u8a62\u6548\u7387\u3002<\/li>\n<li><strong>\u5206\u5340\uff1a<\/strong>\u5c0d\u65bc\u5927\u578b\u6578\u64da\u8868\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528\u5206\u5340\u6280\u8853\uff0c\u5c07\u6578\u64da\u5206\u6563\u5230\u4e0d\u540c\u7684\u7269\u7406\u5340\u57df\uff0c\u4ee5\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\u3002<\/li>\n<\/ul>\n<h2 id=\"3-%e7%a1%ac%e9%ab%94%e5%8d%87%e7%b4%9a-CzWJAUOqaO\">3. \u786c\u9ad4\u5347\u7d1a<\/h2>\n<p>\u5982\u679c\u6578\u64da\u5eab\u7684\u6027\u80fd\u4ecd\u7136\u7121\u6cd5\u6eff\u8db3\u9700\u6c42\uff0c\u53ef\u80fd\u9700\u8981\u8003\u616e\u786c\u9ad4\u5347\u7d1a\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8b70\uff1a<\/p>\n<ul>\n<li><strong>\u589e\u52a0\u5167\u5b58\uff1a<\/strong>\u66f4\u591a\u7684\u5167\u5b58\u53ef\u4ee5\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u7de9\u5b58\u80fd\u529b\uff0c\u5f9e\u800c\u52a0\u5feb\u67e5\u8a62\u901f\u5ea6\u3002<\/li>\n<li><strong>\u4f7f\u7528SSD\uff1a<\/strong>\u56fa\u614b\u786c\u789f\uff08SSD\uff09\u6bd4\u50b3\u7d71\u786c\u789f\uff08HDD\uff09\u5177\u6709\u66f4\u5feb\u7684\u8b80\u5beb\u901f\u5ea6\uff0c\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u6578\u64da\u5eab\u6027\u80fd\u3002<\/li>\n<\/ul>\n<h2 id=\"4-%e7%9b%a3%e6%8e%a7%e5%92%8c%e8%aa%bf%e6%95%b4-CzWJAUOqaO\">4. \u76e3\u63a7\u548c\u8abf\u6574<\/h2>\n<p>\u6301\u7e8c\u76e3\u63a7\u6578\u64da\u5eab\u7684\u6027\u80fd\u662f\u78ba\u4fdd\u5176\u9ad8\u6548\u904b\u884c\u7684\u95dc\u9375\u3002\u4f7f\u7528\u6027\u80fd\u76e3\u63a7\u5de5\u5177\u53ef\u4ee5\u5e6b\u52a9\u8b58\u5225\u74f6\u9838\u548c\u6f5b\u5728\u554f\u984c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u76e3\u63a7\u6307\u6a19\uff1a<\/p>\n<ul>\n<li><strong>\u67e5\u8a62\u57f7\u884c\u6642\u9593\uff1a<\/strong>\u76e3\u63a7\u67e5\u8a62\u7684\u57f7\u884c\u6642\u9593\uff0c\u627e\u51fa\u57f7\u884c\u6642\u9593\u904e\u9577\u7684\u67e5\u8a62\u9032\u884c\u512a\u5316\u3002<\/li>\n<li><strong>\u9396\u5b9a\u60c5\u6cc1\uff1a<\/strong>\u6aa2\u67e5\u6578\u64da\u5eab\u7684\u9396\u5b9a\u60c5\u6cc1\uff0c\u907f\u514d\u56e0\u9396\u5b9a\u5c0e\u81f4\u7684\u6027\u80fd\u4e0b\u964d\u3002<\/li>\n<\/ul>\n<h2 id=\"5-%e4%bd%bf%e7%94%a8%e7%b7%a9%e5%ad%98%e6%8a%80%e8%a1%93-CzWJAUOqaO\">5. \u4f7f\u7528\u7de9\u5b58\u6280\u8853<\/h2>\n<p>\u7de9\u5b58\u6280\u8853\u53ef\u4ee5\u986f\u8457\u6e1b\u5c11\u5c0d\u6578\u64da\u5eab\u7684\u8acb\u6c42\uff0c\u5f9e\u800c\u63d0\u9ad8\u6027\u80fd\u3002\u53ef\u4ee5\u8003\u616e\u4f7f\u7528\u4ee5\u4e0b\u7de9\u5b58\u6280\u8853\uff1a<\/p>\n<ul>\n<li><strong>\u61c9\u7528\u5c64\u7de9\u5b58\uff1a<\/strong>\u5728\u61c9\u7528\u5c64\u4f7f\u7528\u7de9\u5b58\uff08\u5982Redis\u6216Memcached\uff09\u4f86\u5b58\u5132\u983b\u7e41\u8a2a\u554f\u7684\u6578\u64da\u3002<\/li>\n<li><strong>\u67e5\u8a62\u7de9\u5b58\uff1a<\/strong>\u555f\u7528SQL\u67e5\u8a62\u7de9\u5b58\uff0c\u9019\u6a23\u53ef\u4ee5\u5728\u76f8\u540c\u67e5\u8a62\u518d\u6b21\u57f7\u884c\u6642\u76f4\u63a5\u8fd4\u56de\u7d50\u679c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-CzWJAUOqaO\">\u7e3d\u7d50<\/h2>\n<p>\u89e3\u6c7aSQL\u6578\u64da\u5eab\u5361\u9813\u554f\u984c\u9700\u8981\u7d9c\u5408\u8003\u616e\u67e5\u8a62\u512a\u5316\u3001\u6578\u64da\u5eab\u8a2d\u8a08\u3001\u786c\u9ad4\u5347\u7d1a\u3001\u6027\u80fd\u76e3\u63a7\u548c\u7de9\u5b58\u6280\u8853\u7b49\u591a\u65b9\u9762\u7684\u56e0\u7d20\u3002\u901a\u904e\u9019\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u6027\u80fd\uff0c\u78ba\u4fdd\u61c9\u7528\u7a0b\u5e8f\u7684\u6d41\u66a2\u904b\u884c\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u6216<a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u5eab\u9700\u6c42\uff0c\u9019\u5c07\u6709\u52a9\u65bc\u63d0\u5347\u6574\u9ad4\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u6709\u6548\u65b9\u6cd5\u89e3\u6c7aSQL\u6578\u64da\u5eab\u5361\u9813\u554f\u984c\uff0c\u63d0\u5347\u6027\u80fd\uff0c\u512a\u5316\u67e5\u8a62\uff0c\u78ba\u4fdd\u6578\u64da\u8655\u7406\u6d41\u66a2\u7121\u963b\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-163707","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/163707","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=163707"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/163707\/revisions"}],"predecessor-version":[{"id":163708,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/163707\/revisions\/163708"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=163707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=163707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=163707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}