{"id":5396,"date":"2024-11-14T11:05:20","date_gmt":"2024-11-14T03:05:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5396\/"},"modified":"2024-11-14T11:05:20","modified_gmt":"2024-11-14T03:05:20","slug":"mysql%e6%80%8e%e4%b9%88%e5%88%a0%e6%8e%89%e4%b8%bb%e9%94%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5396\/","title":{"rendered":"mysql\u600e\u4e48\u5220\u6389\u4e3b\u952e"},"content":{"rendered":"<blockquote><p>\n  \u8981\u5220\u9664 mysql \u4e2d\u7684\u4e3b\u952e\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u7981\u7528\u5f15\u7528\u7684\u5916\u952e\u7ea6\u675f\u3002\u5220\u9664\u73b0\u6709\u4e3b\u952e\u7ea6\u675f\u3002\u53ef\u9009\uff1a\u4f7f\u7528\u65b0\u7684\u4e3b\u952e\u91cd\u65b0\u521b\u5efa\u8868\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052810422247048.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u5220\u6389\u4e3b\u952e\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u5220\u6389\u4e3b\u952e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5220\u9664 MySQL \u4e2d\u7684\u4e3b\u952e<\/strong><\/p>\n<p><strong>\u5220\u9664\u4e3b\u952e\u7684\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u7981\u7528\u5916\u952e\u7ea6\u675f\uff1a<\/strong><\/p>\n<ul>\n<li>\u5bf9\u4e8e\u5f15\u7528\u8be5\u4e3b\u952e\u7684\u5916\u952e\u8868\uff0c\u4f7f\u7528 ALTER TABLE DROP FOREIGN KEY \u7981\u7528\u5916\u952e\u7ea6\u675f\u3002 <\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5220\u9664\u4e3b\u952e\u7ea6\u675f\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 ALTER TABLE DROP PRIMARY KEY \u5220\u9664\u73b0\u6709\u4e3b\u952e\u7ea6\u675f\u3002 <\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u91cd\u65b0\u521b\u5efa\u8868\uff08\u53ef\u9009\uff09\uff1a<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u9700\u8981\u5728\u5220\u9664\u4e3b\u952e\u540e\u4fdd\u7559\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528 CREATE TABLE \u8bed\u53e5\u91cd\u65b0\u521b\u5efa\u8868\uff0c\u540c\u65f6\u6307\u5b9a\u65b0\u7684\u4e3b\u952e\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>-- \u7981\u7528\u5916\u952e\u7ea6\u675f\nALTER TABLE orders DROP FOREIGN KEY fk_product_id;\n\n-- \u5220\u9664\u4e3b\u952e\u7ea6\u675f\nALTER TABLE products DROP PRIMARY KEY;\n\n-- \u91cd\u65b0\u521b\u5efa\u8868\nCREATE TABLE products (\n  id INT NOT NULL AUTO_INCREMENT,\n  name VARCHAR(255) NOT NULL,\n  PRIMARY KEY (id)\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u5220\u9664\u4e3b\u952e\u4f1a\u6c38\u4e45\u4ece\u8868\u4e2d\u5220\u9664\u6570\u636e\u3002\u8bf7\u5728\u6267\u884c\u6b64\u64cd\u4f5c\u4e4b\u524d\u5907\u4efd\u60a8\u7684\u6570\u636e\u3002<\/li>\n<li>\u5220\u9664\u4e3b\u952e\u540e\uff0c\u8868\u5c06\u4e0d\u518d\u5177\u6709\u552f\u4e00\u6807\u8bc6\u8bb0\u5f55\u7684\u673a\u5236\u3002<\/li>\n<li>\u5bf9\u4e8e\u5177\u6709\u591a\u4e2a\u5916\u952e\u7684\u8868\uff0c\u5fc5\u987b\u7981\u7528\u6240\u6709\u5916\u952e\u7ea6\u675f\u624d\u80fd\u5220\u9664\u4e3b\u952e\u3002<\/li>\n<li>\u5982\u679c\u8868\u4e2d\u5b58\u5728\u552f\u4e00\u7d22\u5f15\u6216\u552f\u4e00\u7ea6\u675f\uff0c\u5219\u4e0d\u80fd\u5220\u9664\u4e3b\u952e\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5220\u6389\u4e3b\u952e\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>\u8981\u5220\u9664 mysql \u4e2d\u7684\u4e3b\u952e\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u7981\u7528\u5f15\u7528\u7684\u5916\u952e\u7ea6\u675f\u3002\u5220\u9664\u73b0\u6709\u4e3b\u952e\u7ea6\u675f\u3002\u53ef\u9009\uff1a\u4f7f\u7528\u65b0\u7684\u4e3b\u952e\u91cd\u65b0\u521b\u5efa\u8868\u3002 \u5982\u4f55\u5220\u9664 MySQL \u4e2d\u7684\u4e3b\u952e \u5220\u9664\u4e3b\u952e\u7684\u6b65\u9aa4\uff1a \u7981\u7528\u5916\u952e\u7ea6\u675f\uff1a \u5bf9\u4e8e\u5f15\u7528\u8be5\u4e3b\u952e\u7684\u5916\u952e\u8868\uff0c\u4f7f\u7528 ALTER TABLE DROP FOREIGN KEY \u7981\u7528\u5916\u952e\u7ea6\u675f\u3002 \u5220\u9664\u4e3b\u952e\u7ea6\u675f\uff1a \u4f7f\u7528 ALTER TABLE DROP PRIMARY KEY \u5220\u9664\u73b0\u6709\u4e3b\u952e\u7ea6\u675f\u3002 \u91cd\u65b0\u521b\u5efa\u8868\uff08\u53ef\u9009\uff09\uff1a \u5982\u679c\u9700\u8981\u5728\u5220\u9664\u4e3b\u952e\u540e\u4fdd\u7559\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528 CREATE TABLE \u8bed\u53e5\u91cd\u65b0\u521b\u5efa\u8868\uff0c\u540c\u65f6\u6307\u5b9a\u65b0\u7684\u4e3b\u952e\u3002 \u793a\u4f8b\uff1a &#8212; \u7981\u7528\u5916\u952e\u7ea6\u675f ALTER TABLE orders DROP FOREIGN KEY fk_product_id; &#8212; \u5220\u9664\u4e3b\u952e\u7ea6\u675f ALTER TABLE products DROP PRIMARY KEY; &#8212; \u91cd\u65b0\u521b\u5efa\u8868 CREATE TABLE products ( id INT NOT [&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-5396","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5396","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=5396"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5396\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}