{"id":6513,"date":"2024-11-14T11:12:40","date_gmt":"2024-11-14T03:12:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6513\/"},"modified":"2024-11-14T11:12:40","modified_gmt":"2024-11-14T03:12:40","slug":"%e6%80%8e%e4%b9%88%e5%88%a0%e9%99%a4mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6513\/","title":{"rendered":"\u600e\u4e48\u5220\u9664mysql\u6570\u636e\u5e93\u6570\u636e"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u5220\u9664 mysql \u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\uff1f\u4f7f\u7528 truncate table \u547d\u4ee4\u5feb\u901f\u5220\u9664\u6240\u6709\u8bb0\u5f55\uff0c\u65e0\u9700\u63d0\u4ea4\u66f4\u6539\u3002\u4f7f\u7528 delete \u8bed\u53e5\u9010\u884c\u5220\u9664\u8bb0\u5f55\uff0c\u53ef\u6307\u5b9a\u6761\u4ef6\u5e76\u89e6\u53d1\u5220\u9664\u89e6\u53d1\u5668\u3002\u663e\u5f0f\u8bbe\u7f6e null \u503c\u5220\u9664\u5217\u4e2d\u7684\u6570\u636e\uff0c\u4fdd\u7559\u8bb0\u5f55\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/05\/2024080519342250044.jpg\" class=\"aligncenter\" title=\"\u600e\u4e48\u5220\u9664mysql\u6570\u636e\u5e93\u6570\u636e\u63d2\u56fe\" alt=\"\u600e\u4e48\u5220\u9664mysql\u6570\u636e\u5e93\u6570\u636e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5220\u9664 MySQL \u6570\u636e\u5e93\u6570\u636e<\/strong><\/p>\n<p>\u5220\u9664 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p><strong>TRUNCATE TABLE<\/strong><\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u6700\u5feb\u7684\u5220\u9664\u6240\u6709\u8bb0\u5f55\u7684\u65b9\u6cd5\uff0c\u5e76\u4e14\u65e0\u9700\u63d0\u4ea4\u66f4\u6539\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>TRUNCATE TABLE table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528 TRUNCATE TABLE \u65f6\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<ul>\n<li>\u5b83\u4f1a\u7acb\u5373\u5220\u9664\u6240\u6709\u8bb0\u5f55\uff0c\u800c\u65e0\u9700\u56de\u6eda<\/li>\n<li>\u5b83\u6bd4 DELETE \u5feb\u5f97\u591a<\/li>\n<li>\u5b83\u4e0d\u4f1a\u89e6\u53d1\u5220\u9664\u89e6\u53d1\u5668<\/li>\n<\/ul>\n<p><strong>DELETE \u8bed\u53e5<\/strong><\/p>\n<p>DELETE \u8bed\u53e5\u7528\u4e8e\u9010\u884c\u5220\u9664\u8bb0\u5f55\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>DELETE FROM table_name\nWHERE condition;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u5220\u9664\u6240\u6709\u540d\u4e3a &#8220;John&#8221; \u7684\u8bb0\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>DELETE FROM users WHERE name = 'John';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528 DELETE \u8bed\u53e5\u65f6\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<ul>\n<li>\u5b83\u9010\u884c\u5220\u9664\u8bb0\u5f55\uff0c\u56e0\u6b64\u53ef\u80fd\u6bd4 TRUNCATE TABLE \u6162<\/li>\n<li>\u5b83\u53ef\u4ee5\u89e6\u53d1\u5220\u9664\u89e6\u53d1\u5668<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528 WHERE \u5b50\u53e5\u6307\u5b9a\u5220\u9664\u6761\u4ef6<\/li>\n<\/ul>\n<p><strong>\u663e\u5f0f\u8bbe\u7f6e NULL \u503c<\/strong><\/p>\n<p>\u5bf9\u4e8e\u67d0\u4e9b\u60c5\u51b5\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u5c06\u5217\u663e\u5f0f\u8bbe\u7f6e\u4e3a NULL \u800c\u4e0d\u662f\u5b8c\u5168\u5220\u9664\u8bb0\u5f55\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>UPDATE table_name SET column_name = NULL\nWHERE condition;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u5c06\u540d\u4e3a &#8220;John&#8221; \u7684\u6240\u6709\u8bb0\u5f55\u7684 &#8220;age&#8221; \u5217\u8bbe\u7f6e\u4e3a NULL\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>UPDATE users SET age = NULL WHERE name = 'John';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528\u6b64\u65b9\u6cd5\u65f6\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<ul>\n<li>\u5b83\u6bd4 TRUNCATE TABLE \u6216 DELETE \u6162<\/li>\n<li>\u5b83\u4ecd\u7136\u4fdd\u7559\u8bb0\u5f55\uff0c\u53ea\u662f\u5c06\u5176\u5217\u503c\u8bbe\u7f6e\u4e3a NULL<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5220\u9664\u6570\u636e\u5e93\u6570\u636e\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>\u5982\u4f55\u5220\u9664 mysql \u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\uff1f\u4f7f\u7528 truncate table \u547d\u4ee4\u5feb\u901f\u5220\u9664\u6240\u6709\u8bb0\u5f55\uff0c\u65e0\u9700\u63d0\u4ea4\u66f4\u6539\u3002\u4f7f\u7528 delete \u8bed\u53e5\u9010\u884c\u5220\u9664\u8bb0\u5f55\uff0c\u53ef\u6307\u5b9a\u6761\u4ef6\u5e76\u89e6\u53d1\u5220\u9664\u89e6\u53d1\u5668\u3002\u663e\u5f0f\u8bbe\u7f6e null \u503c\u5220\u9664\u5217\u4e2d\u7684\u6570\u636e\uff0c\u4fdd\u7559\u8bb0\u5f55\u3002 \u5982\u4f55\u5220\u9664 MySQL \u6570\u636e\u5e93\u6570\u636e \u5220\u9664 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u51e0\u79cd\u65b9\u6cd5\uff1a TRUNCATE TABLE \u8fd9\u662f\u4e00\u4e2a\u6700\u5feb\u7684\u5220\u9664\u6240\u6709\u8bb0\u5f55\u7684\u65b9\u6cd5\uff0c\u5e76\u4e14\u65e0\u9700\u63d0\u4ea4\u66f4\u6539\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a TRUNCATE TABLE table_name; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 TRUNCATE TABLE \u65f6\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a \u5b83\u4f1a\u7acb\u5373\u5220\u9664\u6240\u6709\u8bb0\u5f55\uff0c\u800c\u65e0\u9700\u56de\u6eda \u5b83\u6bd4 DELETE \u5feb\u5f97\u591a \u5b83\u4e0d\u4f1a\u89e6\u53d1\u5220\u9664\u89e6\u53d1\u5668 DELETE \u8bed\u53e5 DELETE \u8bed\u53e5\u7528\u4e8e\u9010\u884c\u5220\u9664\u8bb0\u5f55\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a DELETE FROM table_name WHERE condition; \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff0c\u8981\u5220\u9664\u6240\u6709\u540d\u4e3a &#8220;John&#8221; \u7684\u8bb0\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a DELETE FROM users WHERE name = &#8216;John&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 DELETE [&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-6513","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6513","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=6513"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6513\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}