{"id":5221,"date":"2024-11-14T09:41:30","date_gmt":"2024-11-14T01:41:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5221\/"},"modified":"2024-11-14T09:41:30","modified_gmt":"2024-11-14T01:41:30","slug":"sql-update%e8%af%ad%e5%8f%a5%e7%9a%84%e5%9f%ba%e6%9c%ac%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5221\/","title":{"rendered":"SQL update\u8bed\u53e5\u7684\u57fa\u672c\u7528\u6cd5"},"content":{"rendered":"<blockquote><p>\n  update \u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u6570\u636e\u5e93\u8868\u683c\u4e2d\u7684\u73b0\u6709\u8bb0\u5f55\u3002\u8bed\u6cd5\uff1aupdate table_name set column1 = new_value1, column2 = new_value2, &#8230; where condition;\u3002\u60a8\u53ef\u4ee5\u66f4\u65b0\u591a\u4e2a\u5217\uff0c\u5e76\u4f7f\u7528 where \u5b50\u53e5\u6307\u5b9a\u8981\u66f4\u65b0\u7684\u7279\u5b9a\u884c\u3002update \u8bed\u53e5\u4f1a\u8fd4\u56de\u53d7\u5f71\u54cd\u7684\u884c\u6570\uff0c\u5efa\u8bae\u5728\u6267\u884c\u524d\u8fdb\u884c\u5907\u4efd\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/24\/2024052422092130364.jpg\" class=\"aligncenter\" title=\"SQL update\u8bed\u53e5\u7684\u57fa\u672c\u7528\u6cd5\u63d2\u56fe\" alt=\"SQL update\u8bed\u53e5\u7684\u57fa\u672c\u7528\u6cd5\u63d2\u56fe\" \/><\/p>\n<p><strong>SQL UPDATE \u8bed\u53e5\u7684\u57fa\u672c\u7528\u6cd5<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f UPDATE \u8bed\u53e5\uff1f<\/strong><br \/>UPDATE \u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u6570\u636e\u5e93\u8868\u683c\u4e2d\u73b0\u6709\u7684\u8bb0\u5f55\u3002\u5b83\u5141\u8bb8\u60a8\u6839\u636e\u6307\u5b9a\u6761\u4ef6\u66f4\u65b0\u7279\u5b9a\u5217\u6216\u884c\u7684\u503c\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>UPDATE table_name\nSET column1 = new_value1, column2 = new_value2, ...\nWHERE condition;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>UPDATE customers\nSET name = 'John Smith'\nWHERE customer_id = 1;\n\n-- \u66f4\u65b0\u5217 age \u4e3a 30\uff0c\u6761\u4ef6\u662f customer_id \u4e3a 2\nUPDATE customers\nSET age = 30\nWHERE customer_id = 2;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u66f4\u65b0\u591a\u4e2a\u5217\uff1a<\/strong><br \/>\u60a8\u53ef\u4ee5\u4f7f\u7528\u9017\u53f7\u5206\u9694\u7b26\u5728\u540c\u4e00\u8bed\u53e5\u4e2d\u66f4\u65b0\u591a\u4e2a\u5217\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>-- \u66f4\u65b0\u5217 name\u3001age \u548c address\nUPDATE customers\nSET name = 'Jane Doe', age = 25, address = '123 Main Street'\nWHERE id = 1;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u4f7f\u7528 WHERE \u5b50\u53e5\uff1a<\/strong><br \/>WHERE \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a\u8981\u66f4\u65b0\u7684\u7279\u5b9a\u884c\uff0c\u5b83\u57fa\u4e8e\u67d0\u4e9b\u6761\u4ef6\u3002\u5982\u679c\u6ca1\u6709 WHERE \u5b50\u53e5\uff0c\u5219\u5c06\u66f4\u65b0\u6574\u4e2a\u8868\u683c\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>-- \u66f4\u65b0\u6240\u6709\u5e74\u9f84\u5927\u4e8e 30 \u7684\u5ba2\u6237\u7684 age \u4e3a 35\nUPDATE customers\nSET age = 35\nWHERE age &gt; 30;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 UPDATE \u8bed\u53e5\u65f6\u8981\u5c0f\u5fc3\uff0c\u56e0\u4e3a\u5b83\u53ef\u80fd\u4f1a\u610f\u5916\u4fee\u6539\u5927\u91cf\u6570\u636e\u3002<\/li>\n<li>\u5728\u6267\u884c UPDATE \u8bed\u53e5\u4e4b\u524d\uff0c\u5efa\u8bae\u8fdb\u884c\u5907\u4efd\u3002<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528 NULL \u503c\u66f4\u65b0\u5217\u3002<\/li>\n<li>UPDATE \u8bed\u53e5\u4f1a\u8fd4\u56de\u53d7\u5f71\u54cd\u7684\u884c\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 rowCount \u5c5e\u6027\u83b7\u53d6\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fSQL update\u8bed\u53e5\u7684\u57fa\u672c\u7528\u6cd5\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>update \u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u6570\u636e\u5e93\u8868\u683c\u4e2d\u7684\u73b0\u6709\u8bb0\u5f55\u3002\u8bed\u6cd5\uff1aupdate table_name set column1 = new_value1, column2 = new_value2, &#8230; where condition;\u3002\u60a8\u53ef\u4ee5\u66f4\u65b0\u591a\u4e2a\u5217\uff0c\u5e76\u4f7f\u7528 where \u5b50\u53e5\u6307\u5b9a\u8981\u66f4\u65b0\u7684\u7279\u5b9a\u884c\u3002update \u8bed\u53e5\u4f1a\u8fd4\u56de\u53d7\u5f71\u54cd\u7684\u884c\u6570\uff0c\u5efa\u8bae\u5728\u6267\u884c\u524d\u8fdb\u884c\u5907\u4efd\u3002 SQL UPDATE \u8bed\u53e5\u7684\u57fa\u672c\u7528\u6cd5 \u4ec0\u4e48\u662f UPDATE \u8bed\u53e5\uff1fUPDATE \u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u6570\u636e\u5e93\u8868\u683c\u4e2d\u73b0\u6709\u7684\u8bb0\u5f55\u3002\u5b83\u5141\u8bb8\u60a8\u6839\u636e\u6307\u5b9a\u6761\u4ef6\u66f4\u65b0\u7279\u5b9a\u5217\u6216\u884c\u7684\u503c\u3002 \u8bed\u6cd5\uff1a UPDATE table_name SET column1 = new_value1, column2 = new_value2, &#8230; WHERE condition; \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a UPDATE customers SET name = &#8216;John Smith&#8217; WHERE customer_id = 1; &#8212; \u66f4\u65b0\u5217 age \u4e3a 30\uff0c\u6761\u4ef6\u662f customer_id [&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-5221","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5221","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=5221"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5221\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}