{"id":5231,"date":"2024-11-14T12:06:30","date_gmt":"2024-11-14T04:06:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5231\/"},"modified":"2024-11-14T12:06:30","modified_gmt":"2024-11-14T04:06:30","slug":"mysql%e5%a4%96%e9%94%ae%e5%90%8d%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5231\/","title":{"rendered":"mysql\u5916\u952e\u540d\u600e\u4e48\u5199"},"content":{"rendered":"<blockquote><p>\n  mysql \u4e2d\u5916\u952e\u547d\u540d\u89c4\u5219\u9075\u5faa\u4ee5\u4e0b\u7ea6\u5b9a\uff1a1. \u524d\u7f00\u4e3a\u76f8\u5173\u8868\u540d\u6216\u7f29\u5199\uff1b2. \u5173\u8054\u5217\u540d\u540e\u7f00\u901a\u5e38\u4e0e\u5916\u952e\u5217\u540d\u76f8\u540c\uff0c\u4ee5\u7f29\u5199\u6216\u5168\u79f0\u5f62\u5f0f\uff1b3. \u5efa\u8bae\u4f7f\u7528\u4e0b\u5212\u7ebf\u5206\u9694\u5355\u8bcd\uff0c\u547d\u540d\u6e05\u6670\u3001\u7b80\u6d01\uff0c\u4e0e\u7528\u9014\u76f8\u5173\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/26\/2024052617064725043.jpg\" class=\"aligncenter\" title=\"mysql\u5916\u952e\u540d\u600e\u4e48\u5199\u63d2\u56fe\" alt=\"mysql\u5916\u952e\u540d\u600e\u4e48\u5199\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u5916\u952e\u540d\u4e66\u5199\u89c4\u5219<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong>MySQL \u4e2d\u5916\u952e\u7684\u547d\u540d\u89c4\u5219\u662f\u4ec0\u4e48\uff1f<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong>MySQL \u4e2d\uff0c\u5916\u952e\u7684\u547d\u540d\u89c4\u5219\u9075\u5faa\u4ee5\u4e0b\u7ea6\u5b9a\uff1a<\/p>\n<p><strong>1. \u524d\u7f00<\/strong><\/p>\n<ul>\n<li>\u5bf9\u4e8e\u5305\u542b\u4e00\u4e2a\u5916\u952e\u7684\u8868\uff0c\u5916\u952e\u5217\u540d\u901a\u5e38\u4ee5\u76f8\u5173\u8868\u540d\u6216\u5176\u7f29\u5199\u4f5c\u4e3a\u524d\u7f00\u3002<\/li>\n<li>\u4f8b\u5982\uff0c\u5982\u679c\u6709\u4e00\u4e2a orders \u8868\u548c\u4e00\u4e2a products \u8868\uff0c\u5219 orders \u8868\u4e2d\u7684\u5916\u952e\u5217\u540d\u4e3a product_id\u3002<\/li>\n<\/ul>\n<p><strong>2. \u5173\u8054\u5217\u540d<\/strong><\/p>\n<ul>\n<li>\u540e\u7f00\u901a\u5e38\u4e0e\u5916\u952e\u5217\u540d\u76f8\u540c\uff0c\u4ee5\u7f29\u5199\u6216\u5168\u79f0\u5f62\u5f0f\u3002<\/li>\n<li>\u4f8b\u5982\uff0c\u5728 orders \u8868\u4e2d\uff0c\u5916\u952e\u5217\u540d\u662f product_id\uff0c\u5176\u5173\u8054\u5217\u5728 products \u8868\u4e2d\u4e5f\u79f0\u4e3a id \u6216 product_id\u3002<\/li>\n<\/ul>\n<p><strong>3. \u547d\u540d\u7ea6\u5b9a<\/strong><\/p>\n<ul>\n<li>\u5efa\u8bae\u4f7f\u7528\u4e0b\u5212\u7ebf\u5206\u9694\u5355\u8bcd\uff0c\u4f8b\u5982 product_id\u3002<\/li>\n<li>\u907f\u514d\u4f7f\u7528\u4e0e\u4fdd\u7559\u5b57\u6216\u5176\u4ed6\u6570\u636e\u5e93\u5bf9\u8c61\u76f8\u51b2\u7a81\u7684\u540d\u79f0\u3002<\/li>\n<li>\u5c3d\u91cf\u4f7f\u5916\u952e\u540d\u79f0\u6e05\u6670\u3001\u7b80\u6d01\uff0c\u5e76\u4e14\u4e0e\u5916\u952e\u7684\u7528\u9014\u76f8\u5173\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u5047\u8bbe\u6709\u4e00\u4e2a orders \u8868\u548c\u4e00\u4e2a customers \u8868\uff0c\u5176\u4e2d orders \u8868\u4e2d\u7684 customer_id \u5217\u5f15\u7528 customers \u8868\u4e2d\u7684 id \u5217\u3002\u90a3\u4e48\uff0c\u5916\u952e\u7684\u547d\u540d\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li> <strong>orders<\/strong> \u8868\u4e2d\u7684\u5916\u952e\u5217\u540d\uff1acustomer_id<\/li>\n<li> <strong>customers<\/strong> \u8868\u4e2d\u7684\u5173\u8054\u5217\u540d\uff1aid<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>MySQL \u4e2d\uff0c\u5916\u952e\u5e76\u4e0d\u662f\u5f3a\u5236\u6267\u884c\u7684\u3002<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528 CONSTRAINT \u5b50\u53e5\u663e\u5f0f\u6307\u5b9a\u5916\u952e\uff0c\u5e76\u4f7f\u7528 FOREIGN KEY \u5b50\u53e5\u6307\u5b9a\u5173\u8054\u7684\u5217\u3002<\/li>\n<li>\u5916\u952e\u7684\u547d\u540d\u7ea6\u5b9a\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9879\u76ee\u548c\u56e2\u961f\u7684\u504f\u597d\u800c\u6709\u6240\u4e0d\u540c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5916\u952e\u540d\u600e\u4e48\u5199\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>mysql \u4e2d\u5916\u952e\u547d\u540d\u89c4\u5219\u9075\u5faa\u4ee5\u4e0b\u7ea6\u5b9a\uff1a1. \u524d\u7f00\u4e3a\u76f8\u5173\u8868\u540d\u6216\u7f29\u5199\uff1b2. \u5173\u8054\u5217\u540d\u540e\u7f00\u901a\u5e38\u4e0e\u5916\u952e\u5217\u540d\u76f8\u540c\uff0c\u4ee5\u7f29\u5199\u6216\u5168\u79f0\u5f62\u5f0f\uff1b3. \u5efa\u8bae\u4f7f\u7528\u4e0b\u5212\u7ebf\u5206\u9694\u5355\u8bcd\uff0c\u547d\u540d\u6e05\u6670\u3001\u7b80\u6d01\uff0c\u4e0e\u7528\u9014\u76f8\u5173\u3002 MySQL \u5916\u952e\u540d\u4e66\u5199\u89c4\u5219 \u95ee\u9898\uff1aMySQL \u4e2d\u5916\u952e\u7684\u547d\u540d\u89c4\u5219\u662f\u4ec0\u4e48\uff1f \u56de\u7b54\uff1aMySQL \u4e2d\uff0c\u5916\u952e\u7684\u547d\u540d\u89c4\u5219\u9075\u5faa\u4ee5\u4e0b\u7ea6\u5b9a\uff1a 1. \u524d\u7f00 \u5bf9\u4e8e\u5305\u542b\u4e00\u4e2a\u5916\u952e\u7684\u8868\uff0c\u5916\u952e\u5217\u540d\u901a\u5e38\u4ee5\u76f8\u5173\u8868\u540d\u6216\u5176\u7f29\u5199\u4f5c\u4e3a\u524d\u7f00\u3002 \u4f8b\u5982\uff0c\u5982\u679c\u6709\u4e00\u4e2a orders \u8868\u548c\u4e00\u4e2a products \u8868\uff0c\u5219 orders \u8868\u4e2d\u7684\u5916\u952e\u5217\u540d\u4e3a product_id\u3002 2. \u5173\u8054\u5217\u540d \u540e\u7f00\u901a\u5e38\u4e0e\u5916\u952e\u5217\u540d\u76f8\u540c\uff0c\u4ee5\u7f29\u5199\u6216\u5168\u79f0\u5f62\u5f0f\u3002 \u4f8b\u5982\uff0c\u5728 orders \u8868\u4e2d\uff0c\u5916\u952e\u5217\u540d\u662f product_id\uff0c\u5176\u5173\u8054\u5217\u5728 products \u8868\u4e2d\u4e5f\u79f0\u4e3a id \u6216 product_id\u3002 3. \u547d\u540d\u7ea6\u5b9a \u5efa\u8bae\u4f7f\u7528\u4e0b\u5212\u7ebf\u5206\u9694\u5355\u8bcd\uff0c\u4f8b\u5982 product_id\u3002 \u907f\u514d\u4f7f\u7528\u4e0e\u4fdd\u7559\u5b57\u6216\u5176\u4ed6\u6570\u636e\u5e93\u5bf9\u8c61\u76f8\u51b2\u7a81\u7684\u540d\u79f0\u3002 \u5c3d\u91cf\u4f7f\u5916\u952e\u540d\u79f0\u6e05\u6670\u3001\u7b80\u6d01\uff0c\u5e76\u4e14\u4e0e\u5916\u952e\u7684\u7528\u9014\u76f8\u5173\u3002 \u793a\u4f8b\uff1a \u5047\u8bbe\u6709\u4e00\u4e2a orders \u8868\u548c\u4e00\u4e2a customers \u8868\uff0c\u5176\u4e2d orders \u8868\u4e2d\u7684 customer_id \u5217\u5f15\u7528 customers \u8868\u4e2d\u7684 id \u5217\u3002\u90a3\u4e48\uff0c\u5916\u952e\u7684\u547d\u540d\u5982\u4e0b\uff1a orders [&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-5231","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5231","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=5231"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5231\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}