{"id":6484,"date":"2024-11-14T10:41:24","date_gmt":"2024-11-14T02:41:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6484\/"},"modified":"2024-11-14T10:41:24","modified_gmt":"2024-11-14T02:41:24","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%80%8e%e4%b9%88%e5%88%a0%e9%99%a4%e5%85%83%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6484\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u600e\u4e48\u5220\u9664\u5143\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u4ece mysql \u6570\u636e\u5e93\u4e2d\u5220\u9664\u5143\u7ec4\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 delete \u8bed\u53e5\u5b9e\u73b0\uff0c\u5176\u8bed\u6cd5\u5982\u4e0b\uff1adelete from table_name\uff1a\u6307\u5b9a\u8981\u5220\u9664\u5143\u7ec4\u7684\u8868\u3002where condition\uff1a\u6307\u5b9a\u8981\u5220\u9664\u7684\u5143\u7ec4\u7684\u6761\u4ef6\uff08\u53ef\u9009\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/05\/2024080517273741615.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u5220\u9664\u5143\u7ec4\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u5220\u9664\u5143\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5220\u9664 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u5143\u7ec4<\/strong><\/p>\n<p>\u4ece MySQL \u6570\u636e\u5e93\u4e2d\u5220\u9664\u5143\u7ec4\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u4f7f\u7528 DELETE \u8bed\u53e5\u5b9e\u73b0\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/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\u4ece\u4e2d\u5220\u9664\u5143\u7ec4\u7684\u8868\u3002<\/li>\n<li>condition \u662f\u6307\u5b9a\u8981\u5220\u9664\u54ea\u4e9b\u5143\u7ec4\u7684\u53ef\u9009\u6761\u4ef6\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u5c06\u4ece\u540d\u4e3a users \u7684\u8868\u4e2d\u5220\u9664\u6240\u6709 name \u4e3a John \u7684\u5143\u7ec4\uff1a<\/p>\n<pre>DELETE FROM users\nWHERE name = 'John';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5f71\u54cd\u884c\u6570<\/strong><\/p>\n<p>DELETE \u8bed\u53e5\u5c06\u8fd4\u56de\u53d7\u5f71\u54cd\u7684\u884c\u6570\uff0c\u5373\u88ab\u5220\u9664\u7684\u5143\u7ec4\u6570\u3002\u53ef\u4ee5\u4f7f\u7528 ROW_COUNT() \u51fd\u6570\u83b7\u53d6\u53d7\u5f71\u54cd\u7684\u884c\u6570\uff1a<\/p>\n<pre>SELECT ROW_COUNT();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8c28\u614e\u4f7f\u7528<\/strong><\/p>\n<p>\u4f7f\u7528 DELETE \u8bed\u53e5\u65f6\u8981\u683c\u5916\u5c0f\u5fc3\uff0c\u56e0\u4e3a\u4e00\u65e6\u5143\u7ec4\u88ab\u5220\u9664\uff0c\u5b83\u4eec\u5c06\u6c38\u4e45\u6d88\u5931\u3002\u5efa\u8bae\u5728\u6267\u884c DELETE \u8bed\u53e5\u4e4b\u524d\u4f7f\u7528 SELECT \u8bed\u53e5\u9a8c\u8bc1\u8981\u5220\u9664\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u600e\u4e48\u5220\u9664\u5143\u7ec4\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>\u4ece mysql \u6570\u636e\u5e93\u4e2d\u5220\u9664\u5143\u7ec4\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 delete \u8bed\u53e5\u5b9e\u73b0\uff0c\u5176\u8bed\u6cd5\u5982\u4e0b\uff1adelete from table_name\uff1a\u6307\u5b9a\u8981\u5220\u9664\u5143\u7ec4\u7684\u8868\u3002where condition\uff1a\u6307\u5b9a\u8981\u5220\u9664\u7684\u5143\u7ec4\u7684\u6761\u4ef6\uff08\u53ef\u9009\uff09\u3002 \u5982\u4f55\u5220\u9664 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u5143\u7ec4 \u4ece MySQL \u6570\u636e\u5e93\u4e2d\u5220\u9664\u5143\u7ec4\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u4f7f\u7528 DELETE \u8bed\u53e5\u5b9e\u73b0\u3002 \u8bed\u6cd5 DELETE FROM table_name WHERE condition; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a table_name \u662f\u8981\u4ece\u4e2d\u5220\u9664\u5143\u7ec4\u7684\u8868\u3002 condition \u662f\u6307\u5b9a\u8981\u5220\u9664\u54ea\u4e9b\u5143\u7ec4\u7684\u53ef\u9009\u6761\u4ef6\u3002 \u793a\u4f8b \u4ee5\u4e0b\u793a\u4f8b\u5c06\u4ece\u540d\u4e3a users \u7684\u8868\u4e2d\u5220\u9664\u6240\u6709 name \u4e3a John \u7684\u5143\u7ec4\uff1a DELETE FROM users WHERE name = &#8216;John&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u5f71\u54cd\u884c\u6570 DELETE \u8bed\u53e5\u5c06\u8fd4\u56de\u53d7\u5f71\u54cd\u7684\u884c\u6570\uff0c\u5373\u88ab\u5220\u9664\u7684\u5143\u7ec4\u6570\u3002\u53ef\u4ee5\u4f7f\u7528 ROW_COUNT() \u51fd\u6570\u83b7\u53d6\u53d7\u5f71\u54cd\u7684\u884c\u6570\uff1a SELECT ROW_COUNT(); \u767b\u5f55\u540e\u590d\u5236 \u8c28\u614e\u4f7f\u7528 \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-6484","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6484","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=6484"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6484\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}