{"id":6517,"date":"2024-11-14T14:22:32","date_gmt":"2024-11-14T06:22:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6517\/"},"modified":"2024-11-14T14:22:32","modified_gmt":"2024-11-14T06:22:32","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%80%8e%e4%b9%88%e5%88%a0%e9%99%a4%e8%a1%a8%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6517\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u600e\u4e48\u5220\u9664\u8868\u6570\u636e"},"content":{"rendered":"<blockquote><p>\n  \u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5220\u9664 mysql \u8868\u6570\u636e\uff1a1. truncate table\uff1a\u7acb\u5373\u5220\u9664\u6240\u6709\u6570\u636e\uff0c\u91cd\u7f6e\u81ea\u589e\u4e3b\u952e\u503c\u30022. delete \u8bed\u53e5\uff1a\u9010\u884c\u5220\u9664\u6570\u636e\uff0c\u53ef\u4f7f\u7528 where \u5b50\u53e5\u6307\u5b9a\u6761\u4ef6\u30023. where \u5b50\u53e5\uff1a\u7528\u4e8e\u6307\u5b9a\u8981\u5220\u9664\u7684\u884c\uff0c\u652f\u6301\u6bd4\u8f83\u548c\u903b\u8f91\u8fd0\u7b97\u7b26\u3002\u59cb\u7ec8\u5907\u4efd\u6570\u636e\uff0c\u8c28\u614e\u4f7f\u7528 truncate table\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/05\/2024080519401530138.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u5220\u9664\u8868\u6570\u636e\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u5220\u9664\u8868\u6570\u636e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5220\u9664 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u8868\u6570\u636e<\/strong><\/p>\n<p>MySQL \u6570\u636e\u5e93\u63d0\u4f9b\u4e86\u51e0\u79cd\u65b9\u6cd5\u6765\u5220\u9664\u8868\u6570\u636e\uff0c\u5177\u4f53\u65b9\u6cd5\u53d6\u51b3\u4e8e\u4f60\u60f3\u8981\u5220\u9664\u6570\u636e\u7684\u65b9\u5f0f\u3002<\/p>\n<p><strong>1. TRUNCATE TABLE<\/strong><\/p>\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li>TRUNCATE TABLE \u4f1a\u7acb\u5373\u5220\u9664\u8868\u4e2d\u7684\u6240\u6709\u6570\u636e\uff0c\u5305\u62ec\u81ea\u589e\u4e3b\u952e\u503c\u3002<\/li>\n<li>\u5b83\u6bd4 DELETE \u8bed\u53e5\u66f4\u6709\u6548\u7387\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4f1a\u9010\u884c\u5220\u9664\u6570\u636e\u3002<\/li>\n<li>\u5b83\u4f1a\u91cd\u7f6e\u8868\u7684\u81ea\u589e\u4e3b\u952e\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>TRUNCATE TABLE table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>TRUNCATE TABLE employees;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. DELETE \u8bed\u53e5<\/strong><\/p>\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li>DELETE \u8bed\u53e5\u9010\u884c\u5220\u9664\u8868\u4e2d\u7684\u6570\u636e\u3002<\/li>\n<li>\u4f60\u53ef\u4ee5\u4f7f\u7528 WHERE \u5b50\u53e5\u6307\u5b9a\u8981\u5220\u9664\u54ea\u4e9b\u884c\u3002<\/li>\n<\/ul>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>DELETE FROM table_name WHERE condition;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>DELETE FROM employees WHERE salary &gt; 100000;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. WHERE \u5b50\u53e5<\/strong><\/p>\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li>WHERE \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a\u8981\u5220\u9664\u54ea\u4e9b\u884c\u3002<\/li>\n<li>\u5b83\u652f\u6301\u5404\u79cd\u6bd4\u8f83\u8fd0\u7b97\u7b26\u548c\u903b\u8f91\u8fd0\u7b97\u7b26\u3002<\/li>\n<\/ul>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>DELETE FROM table_name WHERE column_name operator value;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>DELETE FROM employees WHERE department = 'Sales';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728\u4f7f\u7528 TRUNCATE TABLE \u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u771f\u7684\u60f3\u5220\u9664\u6240\u6709\u6570\u636e\uff0c\u56e0\u4e3a\u6b64\u64cd\u4f5c\u4e0d\u53ef\u9006\u8f6c\u3002<\/li>\n<li>\u5982\u679c\u53ea\u5220\u9664\u90e8\u5206\u6570\u636e\uff0c\u8bf7\u4f7f\u7528 DELETE \u8bed\u53e5\u3002<\/li>\n<li>\u59cb\u7ec8\u5907\u4efd\u4f60\u7684\u6570\u636e\uff0c\u4ee5\u4fbf\u5728\u610f\u5916\u60c5\u51b5\u4e0b\u6062\u590d\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u600e\u4e48\u5220\u9664\u8868\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>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5220\u9664 mysql \u8868\u6570\u636e\uff1a1. truncate table\uff1a\u7acb\u5373\u5220\u9664\u6240\u6709\u6570\u636e\uff0c\u91cd\u7f6e\u81ea\u589e\u4e3b\u952e\u503c\u30022. delete \u8bed\u53e5\uff1a\u9010\u884c\u5220\u9664\u6570\u636e\uff0c\u53ef\u4f7f\u7528 where \u5b50\u53e5\u6307\u5b9a\u6761\u4ef6\u30023. where \u5b50\u53e5\uff1a\u7528\u4e8e\u6307\u5b9a\u8981\u5220\u9664\u7684\u884c\uff0c\u652f\u6301\u6bd4\u8f83\u548c\u903b\u8f91\u8fd0\u7b97\u7b26\u3002\u59cb\u7ec8\u5907\u4efd\u6570\u636e\uff0c\u8c28\u614e\u4f7f\u7528 truncate table\u3002 \u5982\u4f55\u5220\u9664 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u8868\u6570\u636e MySQL \u6570\u636e\u5e93\u63d0\u4f9b\u4e86\u51e0\u79cd\u65b9\u6cd5\u6765\u5220\u9664\u8868\u6570\u636e\uff0c\u5177\u4f53\u65b9\u6cd5\u53d6\u51b3\u4e8e\u4f60\u60f3\u8981\u5220\u9664\u6570\u636e\u7684\u65b9\u5f0f\u3002 1. TRUNCATE TABLE \u8bf4\u660e\uff1a TRUNCATE TABLE \u4f1a\u7acb\u5373\u5220\u9664\u8868\u4e2d\u7684\u6240\u6709\u6570\u636e\uff0c\u5305\u62ec\u81ea\u589e\u4e3b\u952e\u503c\u3002 \u5b83\u6bd4 DELETE \u8bed\u53e5\u66f4\u6709\u6548\u7387\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4f1a\u9010\u884c\u5220\u9664\u6570\u636e\u3002 \u5b83\u4f1a\u91cd\u7f6e\u8868\u7684\u81ea\u589e\u4e3b\u952e\u503c\u3002 \u8bed\u6cd5\uff1a TRUNCATE TABLE table_name; \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a TRUNCATE TABLE employees; \u767b\u5f55\u540e\u590d\u5236 2. DELETE \u8bed\u53e5 \u8bf4\u660e\uff1a DELETE \u8bed\u53e5\u9010\u884c\u5220\u9664\u8868\u4e2d\u7684\u6570\u636e\u3002 \u4f60\u53ef\u4ee5\u4f7f\u7528 WHERE \u5b50\u53e5\u6307\u5b9a\u8981\u5220\u9664\u54ea\u4e9b\u884c\u3002 \u8bed\u6cd5\uff1a DELETE FROM table_name WHERE condition; \u767b\u5f55\u540e\u590d\u5236 [&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-6517","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6517","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=6517"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6517\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}