{"id":5509,"date":"2024-11-14T08:00:38","date_gmt":"2024-11-14T00:00:38","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5509\/"},"modified":"2024-11-14T08:00:38","modified_gmt":"2024-11-14T00:00:38","slug":"mysql%e8%a7%86%e5%9b%be%e6%80%8e%e4%b9%88%e5%88%9b%e5%bb%ba","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5509\/","title":{"rendered":"mysql\u89c6\u56fe\u600e\u4e48\u521b\u5efa"},"content":{"rendered":"<blockquote><p>\n  \u89c6\u56fe\u662f\u4e00\u79cd\u4ece\u5176\u4ed6\u8868\u68c0\u7d22\u6570\u636e\u7684\u865a\u62df\u8868\uff0c\u4e0d\u4f1a\u5b58\u50a8\u5b9e\u9645\u6570\u636e\u3002\u521b\u5efa\u89c6\u56fe\u7684\u6b65\u9aa4\u5305\u62ec\uff1a1. \u9009\u62e9\u540d\u79f0\uff1b2. \u6307\u5b9a\u8868\uff1b3. \u9009\u62e9\u5217\uff1b4. \u5e94\u7528\u6761\u4ef6\uff08\u53ef\u9009\uff09\uff1b5. \u6267\u884c\u67e5\u8be2\u3002\u4f7f\u7528\u793a\u4f8b\uff1a\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;customer_view&#8221; \u7684\u89c6\u56fe\uff0c\u4ece &#8220;customers&#8221; \u8868\u4e2d\u68c0\u7d22 id\u3001name \u548c email \u5217\uff1acreate view customer_view as select id, name, email from customers;\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/29\/2024052905332454761.jpg\" class=\"aligncenter\" title=\"mysql\u89c6\u56fe\u600e\u4e48\u521b\u5efa\u63d2\u56fe\" alt=\"mysql\u89c6\u56fe\u600e\u4e48\u521b\u5efa\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u521b\u5efa MySQL \u89c6\u56fe<\/strong><\/p>\n<p><strong>\u5b9a\u4e49\uff1a<\/strong><br \/>\u89c6\u56fe\u662f\u4e00\u79cd\u865a\u62df\u8868\uff0c\u5b83\u4ece\u5176\u4ed6\u8868\u4e2d\u68c0\u7d22\u6570\u636e\uff0c\u5c31\u50cf\u4e00\u4e2a\u8868\u4e00\u6837\uff0c\u4f46\u4e0d\u4f1a\u5b58\u50a8\u4efb\u4f55\u5b9e\u9645\u6570\u636e\u3002<\/p>\n<p><strong>\u521b\u5efa\u89c6\u56fe\u7684\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u9009\u62e9\u4e00\u4e2a\u540d\u79f0\uff1a<\/strong>\u4e3a\u60a8\u7684\u89c6\u56fe\u9009\u62e9\u4e00\u4e2a\u6709\u610f\u4e49\u7684\u540d\u79f0\u3002<\/li>\n<li> <strong>\u6307\u5b9a\u8868\uff1a<\/strong>\u6307\u5b9a\u60a8\u5e0c\u671b\u89c6\u56fe\u4ece\u5176\u68c0\u7d22\u6570\u636e\u7684\u8868\u3002<\/li>\n<li> <strong>\u9009\u62e9\u5217\uff1a<\/strong>\u9009\u62e9\u60a8\u5e0c\u671b\u5728\u89c6\u56fe\u4e2d\u5305\u542b\u7684\u5217\u3002<\/li>\n<li> <strong>\u5e94\u7528\u6761\u4ef6\uff1a<\/strong>\u5982\u679c\u9700\u8981\uff0c\u60a8\u53ef\u4ee5\u5e94\u7528\u6761\u4ef6\u6765\u8fc7\u6ee4\u89c6\u56fe\u4e2d\u7684\u6570\u636e\u3002<\/li>\n<li> <strong>\u6267\u884c\u67e5\u8be2\uff1a<\/strong>\u4f7f\u7528 CREATE VIEW \u8bed\u53e5\u6267\u884c\u67e5\u8be2\u4ee5\u521b\u5efa\u89c6\u56fe\u3002<\/li>\n<\/ol>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>CREATE VIEW [view_name] AS\nSELECT [column_list]\nFROM [table_list]\nWHERE [condition];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;customer_view&#8221; \u7684\u89c6\u56fe\uff0c\u8be5\u89c6\u56fe\u4ece &#8220;customers&#8221; \u8868\u4e2d\u68c0\u7d22 id\u3001name \u548c email \u5217\uff1a<\/p>\n<pre>CREATE VIEW customer_view AS\nSELECT id, name, email\nFROM customers;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u89c6\u56fe\uff1a<\/strong><\/p>\n<p>\u521b\u5efa\u89c6\u56fe\u540e\uff0c\u60a8\u53ef\u4ee5\u50cf\u4f7f\u7528\u666e\u901a\u8868\u4e00\u6837\u4f7f\u7528\u5b83\u8fdb\u884c\u67e5\u8be2\u548c\u66f4\u65b0\uff1a<\/p>\n<p><strong>\u67e5\u8be2\u89c6\u56fe\uff1a<\/strong><\/p>\n<pre>SELECT * FROM customer_view;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u66f4\u65b0\u89c6\u56fe\uff1a<\/strong><\/p>\n<p>\u89c6\u56fe\u662f\u53ea\u8bfb\u7684\uff0c\u56e0\u6b64\u60a8\u65e0\u6cd5\u76f4\u63a5\u66f4\u65b0\u89c6\u56fe\u4e2d\u7684\u6570\u636e\u3002\u8981\u66f4\u65b0\u89c6\u56fe\u4e2d\u7684\u6570\u636e\uff0c\u60a8\u9700\u8981\u66f4\u65b0\u89c6\u56fe\u7684\u57fa\u7840\u8868\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u89c6\u56fe\u600e\u4e48\u521b\u5efa\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89c6\u56fe\u662f\u4e00\u79cd\u4ece\u5176\u4ed6\u8868\u68c0\u7d22\u6570\u636e\u7684\u865a\u62df\u8868\uff0c\u4e0d\u4f1a\u5b58\u50a8\u5b9e\u9645\u6570\u636e\u3002\u521b\u5efa\u89c6\u56fe\u7684\u6b65\u9aa4\u5305\u62ec\uff1a1. \u9009\u62e9\u540d\u79f0\uff1b2. \u6307\u5b9a\u8868\uff1b3. \u9009\u62e9\u5217\uff1b4. \u5e94\u7528\u6761\u4ef6\uff08\u53ef\u9009\uff09\uff1b5. \u6267\u884c\u67e5\u8be2\u3002\u4f7f\u7528\u793a\u4f8b\uff1a\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;customer_view&#8221; \u7684\u89c6\u56fe\uff0c\u4ece &#8220;customers&#8221; \u8868\u4e2d\u68c0\u7d22 id\u3001name \u548c email \u5217\uff1acreate view customer_view as select id, name, email from customers;\u3002 \u5982\u4f55\u521b\u5efa MySQL \u89c6\u56fe \u5b9a\u4e49\uff1a\u89c6\u56fe\u662f\u4e00\u79cd\u865a\u62df\u8868\uff0c\u5b83\u4ece\u5176\u4ed6\u8868\u4e2d\u68c0\u7d22\u6570\u636e\uff0c\u5c31\u50cf\u4e00\u4e2a\u8868\u4e00\u6837\uff0c\u4f46\u4e0d\u4f1a\u5b58\u50a8\u4efb\u4f55\u5b9e\u9645\u6570\u636e\u3002 \u521b\u5efa\u89c6\u56fe\u7684\u6b65\u9aa4\uff1a \u9009\u62e9\u4e00\u4e2a\u540d\u79f0\uff1a\u4e3a\u60a8\u7684\u89c6\u56fe\u9009\u62e9\u4e00\u4e2a\u6709\u610f\u4e49\u7684\u540d\u79f0\u3002 \u6307\u5b9a\u8868\uff1a\u6307\u5b9a\u60a8\u5e0c\u671b\u89c6\u56fe\u4ece\u5176\u68c0\u7d22\u6570\u636e\u7684\u8868\u3002 \u9009\u62e9\u5217\uff1a\u9009\u62e9\u60a8\u5e0c\u671b\u5728\u89c6\u56fe\u4e2d\u5305\u542b\u7684\u5217\u3002 \u5e94\u7528\u6761\u4ef6\uff1a\u5982\u679c\u9700\u8981\uff0c\u60a8\u53ef\u4ee5\u5e94\u7528\u6761\u4ef6\u6765\u8fc7\u6ee4\u89c6\u56fe\u4e2d\u7684\u6570\u636e\u3002 \u6267\u884c\u67e5\u8be2\uff1a\u4f7f\u7528 CREATE VIEW \u8bed\u53e5\u6267\u884c\u67e5\u8be2\u4ee5\u521b\u5efa\u89c6\u56fe\u3002 \u8bed\u6cd5\uff1a CREATE VIEW [view_name] AS SELECT [column_list] FROM [table_list] WHERE [condition]; \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a \u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;customer_view&#8221; \u7684\u89c6\u56fe\uff0c\u8be5\u89c6\u56fe\u4ece &#8220;customers&#8221; \u8868\u4e2d\u68c0\u7d22 id\u3001name [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5509","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5509"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5509\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}