{"id":6459,"date":"2024-11-14T12:12:14","date_gmt":"2024-11-14T04:12:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6459\/"},"modified":"2024-11-14T12:12:14","modified_gmt":"2024-11-14T04:12:14","slug":"%e6%80%8e%e4%b9%88%e6%b8%85%e7%a9%bamysql%e7%9a%84%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6459\/","title":{"rendered":"\u600e\u4e48\u6e05\u7a7amysql\u7684\u6570\u636e\u5e93"},"content":{"rendered":"<blockquote><p>\n  \u8981\u6e05\u7a7a mysql \u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528 truncate table \u547d\u4ee4\uff08\u76f4\u63a5\u5220\u9664\u6240\u6709\u6570\u636e\uff0c\u901f\u5ea6\u5feb\uff09\uff0c\u6216 delete \u547d\u4ee4\uff08\u9010\u884c\u5220\u9664\uff0c\u53ef\u6761\u4ef6\u5220\u9664\uff09\u3002\u6ce8\u610f\uff1atruncate table \u547d\u4ee4\u4e0d\u80fd\u7528\u4e8e\u6709\u5916\u952e\u7ea6\u675f\u7684\u8868\uff0c\u800c delete \u547d\u4ee4\u53ef\u4ee5\u4f7f\u7528 where \u5b50\u53e5\u6709\u6761\u4ef6\u5220\u9664\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/05\/2024080507550961130.jpg\" class=\"aligncenter\" title=\"\u600e\u4e48\u6e05\u7a7amysql\u7684\u6570\u636e\u5e93\u63d2\u56fe\" alt=\"\u600e\u4e48\u6e05\u7a7amysql\u7684\u6570\u636e\u5e93\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6e05\u7a7a MySQL \u6570\u636e\u5e93<\/strong><\/p>\n<p>\u6e05\u7a7a MySQL \u6570\u636e\u5e93\u662f\u4e00\u4e2a\u7b80\u5355\u5feb\u6377\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528 TRUNCATE TABLE \u547d\u4ee4<\/strong><\/p>\n<p>TRUNCATE TABLE \u547d\u4ee4\u4f1a\u7acb\u5373\u5220\u9664\u8868\u4e2d\u7684\u6240\u6709\u6570\u636e\uff0c\u4e0d\u4f1a\u8bb0\u5f55\u4e8b\u52a1\u65e5\u5fd7\u3002\u5b83\u6bd4 DELETE \u547d\u4ee4\u66f4\u5feb\uff0c\u56e0\u4e3a\u4e0d\u9700\u8981\u68c0\u67e5\u7ea6\u675f\u6216\u89e6\u53d1\u5668\u3002<\/p>\n<p>\u8bed\u6cd5\uff1a<\/p>\n<pre>TRUNCATE TABLE table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre>TRUNCATE TABLE my_table;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528 DELETE \u547d\u4ee4<\/strong><\/p>\n<p>DELETE \u547d\u4ee4\u4f1a\u9010\u884c\u5220\u9664\u8868\u4e2d\u7684\u6570\u636e\uff0c\u8bb0\u5f55\u4e8b\u52a1\u65e5\u5fd7\u3002\u5b83\u6bd4 TRUNCATE TABLE \u547d\u4ee4\u66f4\u6162\uff0c\u4f46\u53ef\u4ee5\u66f4\u7cbe\u786e\u5730\u63a7\u5236\u5220\u9664\u8fc7\u7a0b\u3002<\/p>\n<p>\u8bed\u6cd5\uff1a<\/p>\n<pre>DELETE FROM table_name [WHERE condition];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre>DELETE FROM my_table WHERE id &gt; 10;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>TRUNCATE TABLE \u548c DELETE \u547d\u4ee4\u90fd\u662f\u7834\u574f\u6027\u64cd\u4f5c\uff0c\u4f1a\u6c38\u4e45\u5220\u9664\u6570\u636e\u3002<\/li>\n<li>TRUNCATE TABLE \u547d\u4ee4\u4e0d\u80fd\u7528\u4e8e\u6709\u5916\u952e\u7ea6\u675f\u7684\u8868\u3002<\/li>\n<li>DELETE \u547d\u4ee4\u53ef\u4ee5\u5305\u542b WHERE \u5b50\u53e5\u4ee5\u6709\u6761\u4ef6\u5730\u5220\u9664\u6570\u636e\u3002<\/li>\n<\/ul>\n<p><strong>\u989d\u5916\u63d0\u793a\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728\u4f7f\u7528 TRUNCATE TABLE \u6216 DELETE \u547d\u4ee4\u4e4b\u524d\uff0c\u5efa\u8bae\u5148\u5907\u4efd\u6570\u636e\u5e93\u3002<\/li>\n<li>\u5982\u679c\u9700\u8981\u4fdd\u7559\u8868\u7ed3\u6784\uff0c\u8bf7\u4f7f\u7528 TRUNCATE TABLE \u547d\u4ee4\u3002<\/li>\n<li>\u5982\u679c\u9700\u8981\u66f4\u7cbe\u786e\u5730\u63a7\u5236\u5220\u9664\u8fc7\u7a0b\uff0c\u8bf7\u4f7f\u7528 DELETE \u547d\u4ee4\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u6e05\u7a7a\u7684\u6570\u636e\u5e93\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\u6e05\u7a7a mysql \u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528 truncate table \u547d\u4ee4\uff08\u76f4\u63a5\u5220\u9664\u6240\u6709\u6570\u636e\uff0c\u901f\u5ea6\u5feb\uff09\uff0c\u6216 delete \u547d\u4ee4\uff08\u9010\u884c\u5220\u9664\uff0c\u53ef\u6761\u4ef6\u5220\u9664\uff09\u3002\u6ce8\u610f\uff1atruncate table \u547d\u4ee4\u4e0d\u80fd\u7528\u4e8e\u6709\u5916\u952e\u7ea6\u675f\u7684\u8868\uff0c\u800c delete \u547d\u4ee4\u53ef\u4ee5\u4f7f\u7528 where \u5b50\u53e5\u6709\u6761\u4ef6\u5220\u9664\u3002 \u6e05\u7a7a MySQL \u6570\u636e\u5e93 \u6e05\u7a7a MySQL \u6570\u636e\u5e93\u662f\u4e00\u4e2a\u7b80\u5355\u5feb\u6377\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a \u65b9\u6cd5 1\uff1a\u4f7f\u7528 TRUNCATE TABLE \u547d\u4ee4 TRUNCATE TABLE \u547d\u4ee4\u4f1a\u7acb\u5373\u5220\u9664\u8868\u4e2d\u7684\u6240\u6709\u6570\u636e\uff0c\u4e0d\u4f1a\u8bb0\u5f55\u4e8b\u52a1\u65e5\u5fd7\u3002\u5b83\u6bd4 DELETE \u547d\u4ee4\u66f4\u5feb\uff0c\u56e0\u4e3a\u4e0d\u9700\u8981\u68c0\u67e5\u7ea6\u675f\u6216\u89e6\u53d1\u5668\u3002 \u8bed\u6cd5\uff1a TRUNCATE TABLE table_name; \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a TRUNCATE TABLE my_table; \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5 2\uff1a\u4f7f\u7528 DELETE \u547d\u4ee4 DELETE \u547d\u4ee4\u4f1a\u9010\u884c\u5220\u9664\u8868\u4e2d\u7684\u6570\u636e\uff0c\u8bb0\u5f55\u4e8b\u52a1\u65e5\u5fd7\u3002\u5b83\u6bd4 TRUNCATE TABLE \u547d\u4ee4\u66f4\u6162\uff0c\u4f46\u53ef\u4ee5\u66f4\u7cbe\u786e\u5730\u63a7\u5236\u5220\u9664\u8fc7\u7a0b\u3002 \u8bed\u6cd5\uff1a DELETE FROM table_name [WHERE condition]; [&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-6459","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6459","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=6459"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6459\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}