{"id":6486,"date":"2024-11-14T12:07:41","date_gmt":"2024-11-14T04:07:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6486\/"},"modified":"2024-11-14T12:07:41","modified_gmt":"2024-11-14T04:07:41","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%80%8e%e4%b9%88%e6%9d%a1%e4%bb%b6%e5%88%a0%e9%99%a4","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6486\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u600e\u4e48\u6761\u4ef6\u5220\u9664"},"content":{"rendered":"<blockquote><p>\n  mysql \u4e2d\u4f7f\u7528\u6761\u4ef6\u5220\u9664\uff0c\u5373\u901a\u8fc7\u6307\u5b9a\u6761\u4ef6\u6709\u9009\u62e9\u5730\u5220\u9664\u6570\u636e\uff0c\u8bed\u6cd5\u4e3a delete from table_name where condition\uff0c\u5176\u4e2d condition \u6307\u5b9a\u5220\u9664\u6761\u4ef6\uff0c\u5982\u5220\u9664\u7279\u5b9a id\u3001\u8303\u56f4\u5185\u7684\u8bb0\u5f55\u3001\u6ee1\u8db3\u591a\u4e2a\u6761\u4ef6\u6216\u5b50\u67e5\u8be2\u7684\u8bb0\u5f55\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6761\u4ef6\u5220\u9664\u4e0d\u53ef\u9006\uff0c\u8bf7\u5907\u4efd\u6570\u636e\uff0c\u8c28\u614e\u6307\u5b9a\u6761\u4ef6\uff0c\u4ee5\u514d\u610f\u5916\u5220\u9664\u6240\u6709\u8bb0\u5f55\u3002truncate \u8bed\u53e5\u53ef\u7528\u4e8e\u66f4\u5feb\u5730\u5220\u9664\u6240\u6709\u8bb0\u5f55\uff0c\u4f46\u4e0d\u4f1a\u89e6\u53d1\u7ea7\u8054\u5220\u9664\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/05\/2024080517282690697.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u6761\u4ef6\u5220\u9664\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u6761\u4ef6\u5220\u9664\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u4e2d\u4f7f\u7528\u6761\u4ef6\u5220\u9664<\/strong><\/p>\n<p>\u5728 MySQL \u6570\u636e\u5e93\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 DELETE \u8bed\u53e5\u6765\u5220\u9664\u6570\u636e\uff0c\u901a\u8fc7\u6307\u5b9a\u6761\u4ef6\u53ef\u4ee5\u5b9e\u73b0\u6709\u9009\u62e9\u5730\u5220\u9664\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>DELETE FROM table_name\nWHERE condition;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>table_name \u662f\u8981\u5220\u9664\u6570\u636e\u8868\u7684\u540d\u79f0\u3002<\/li>\n<li>WHERE \u5b50\u53e5\u6307\u5b9a\u5220\u9664\u6761\u4ef6\u3002<\/li>\n<\/ul>\n<p><strong>\u6761\u4ef6\u5220\u9664\u793a\u4f8b\uff1a<\/strong><\/p>\n<p><strong>\u5220\u9664\u7279\u5b9a ID \u7684\u8bb0\u5f55\uff1a<\/strong><\/p>\n<pre>DELETE FROM employees\nWHERE employee_id = 100;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5220\u9664\u67d0\u4e9b\u8303\u56f4\u5185\u7684\u8bb0\u5f55\uff1a<\/strong><\/p>\n<pre>DELETE FROM orders\nWHERE order_date BETWEEN '2023-01-01' AND '2023-03-31';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5220\u9664\u6ee1\u8db3\u591a\u4e2a\u6761\u4ef6\u7684\u8bb0\u5f55\uff1a<\/strong><\/p>\n<pre>DELETE FROM customers\nWHERE city = 'London' AND status = 'active';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5220\u9664\u6ee1\u8db3\u5b50\u67e5\u8be2\u6761\u4ef6\u7684\u8bb0\u5f55\uff1a<\/strong><\/p>\n<pre>DELETE FROM products\nWHERE price &gt; (\n    SELECT MAX(price) FROM products\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u6761\u4ef6\u5220\u9664\u64cd\u4f5c\u662f\u4e0d\u53ef\u9006\u7684\uff0c\u8bf7\u786e\u4fdd\u5728\u6267\u884c\u524d\u5df2\u5907\u4efd\u6570\u636e\u3002<\/li>\n<li>\u5982\u679c\u6761\u4ef6\u4e0d\u6307\u5b9a\u6216\u6307\u5b9a\u4e0d\u5f53\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u610f\u5916\u5730\u5220\u9664\u6240\u6709\u8bb0\u5f55\u3002<\/li>\n<li>\u4e5f\u53ef\u4ee5\u4f7f\u7528 TRUNCATE \u8bed\u53e5\u6765\u5220\u9664\u8868\u4e2d\u7684\u6240\u6709\u8bb0\u5f55\uff0c\u4f46\u5b83\u6bd4 DELETE \u66f4\u5feb\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4f1a\u89e6\u53d1\u7ea7\u8054\u5220\u9664\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u600e\u4e48\u6761\u4ef6\u5220\u9664\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\u4f7f\u7528\u6761\u4ef6\u5220\u9664\uff0c\u5373\u901a\u8fc7\u6307\u5b9a\u6761\u4ef6\u6709\u9009\u62e9\u5730\u5220\u9664\u6570\u636e\uff0c\u8bed\u6cd5\u4e3a delete from table_name where condition\uff0c\u5176\u4e2d condition \u6307\u5b9a\u5220\u9664\u6761\u4ef6\uff0c\u5982\u5220\u9664\u7279\u5b9a id\u3001\u8303\u56f4\u5185\u7684\u8bb0\u5f55\u3001\u6ee1\u8db3\u591a\u4e2a\u6761\u4ef6\u6216\u5b50\u67e5\u8be2\u7684\u8bb0\u5f55\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6761\u4ef6\u5220\u9664\u4e0d\u53ef\u9006\uff0c\u8bf7\u5907\u4efd\u6570\u636e\uff0c\u8c28\u614e\u6307\u5b9a\u6761\u4ef6\uff0c\u4ee5\u514d\u610f\u5916\u5220\u9664\u6240\u6709\u8bb0\u5f55\u3002truncate \u8bed\u53e5\u53ef\u7528\u4e8e\u66f4\u5feb\u5730\u5220\u9664\u6240\u6709\u8bb0\u5f55\uff0c\u4f46\u4e0d\u4f1a\u89e6\u53d1\u7ea7\u8054\u5220\u9664\u3002 MySQL \u4e2d\u4f7f\u7528\u6761\u4ef6\u5220\u9664 \u5728 MySQL \u6570\u636e\u5e93\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 DELETE \u8bed\u53e5\u6765\u5220\u9664\u6570\u636e\uff0c\u901a\u8fc7\u6307\u5b9a\u6761\u4ef6\u53ef\u4ee5\u5b9e\u73b0\u6709\u9009\u62e9\u5730\u5220\u9664\u3002 \u8bed\u6cd5\uff1a DELETE FROM table_name WHERE condition; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a table_name \u662f\u8981\u5220\u9664\u6570\u636e\u8868\u7684\u540d\u79f0\u3002 WHERE \u5b50\u53e5\u6307\u5b9a\u5220\u9664\u6761\u4ef6\u3002 \u6761\u4ef6\u5220\u9664\u793a\u4f8b\uff1a \u5220\u9664\u7279\u5b9a ID \u7684\u8bb0\u5f55\uff1a DELETE FROM employees WHERE employee_id = 100; \u767b\u5f55\u540e\u590d\u5236 \u5220\u9664\u67d0\u4e9b\u8303\u56f4\u5185\u7684\u8bb0\u5f55\uff1a DELETE FROM orders WHERE order_date BETWEEN &#8216;2023-01-01&#8217; AND &#8216;2023-03-31&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u5220\u9664\u6ee1\u8db3\u591a\u4e2a\u6761\u4ef6\u7684\u8bb0\u5f55\uff1a 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-6486","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6486","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=6486"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6486\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}