{"id":5264,"date":"2024-11-14T11:51:01","date_gmt":"2024-11-14T03:51:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5264\/"},"modified":"2024-11-14T11:51:01","modified_gmt":"2024-11-14T03:51:01","slug":"mysql%e6%80%8e%e4%b9%88%e4%bd%bf%e7%94%a8update","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5264\/","title":{"rendered":"mysql\u600e\u4e48\u4f7f\u7528update"},"content":{"rendered":"<blockquote><p>\n  mysql update \u8bed\u53e5\u7528\u4e8e\u66f4\u65b0\u73b0\u6709\u8bb0\u5f55\uff0c\u8bed\u6cd5\u4e3a\uff1aupdate table_name set column1 = value1, &#8230; where condition\u3002\u5176\u6b65\u9aa4\u5305\u62ec\uff1a\u786e\u5b9a\u8868\u548c\u5217\u3002\u6307\u5b9a\u66f4\u65b0\u503c\u3002\u6dfb\u52a0 where \u5b50\u53e5\u6307\u5b9a\u66f4\u65b0\u6761\u4ef6\u3002\u6267\u884c update \u8bed\u53e5\u4ee5\u66f4\u65b0\u8bb0\u5f55\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/26\/2024052617572557601.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u4f7f\u7528update\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u4f7f\u7528update\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL UPDATE \u8bed\u53e5<\/strong><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 UPDATE \u8bed\u53e5\uff1f<\/strong><\/p>\n<p>UPDATE \u8bed\u53e5\u7528\u4e8e\u66f4\u65b0\u8868\u4e2d\u73b0\u6709\u7684\u8bb0\u5f55\u3002\u5176\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>UPDATE table_name\nSET column1 = value1, column2 = value2, ...\nWHERE condition;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li> <strong>table_name<\/strong>\uff1a\u8981\u66f4\u65b0\u7684\u8868\u7684\u540d\u79f0\u3002<\/li>\n<li> <strong>column1, column2, &#8230;<\/strong>\uff1a\u8981\u66f4\u65b0\u7684\u5217\u7684\u540d\u79f0\u3002<\/li>\n<li> <strong>value1, value2, &#8230;<\/strong>\uff1a\u8981\u66f4\u65b0\u7684\u503c\u3002<\/li>\n<li> <strong>condition<\/strong>\uff1a\u66f4\u65b0\u6761\u4ef6\uff0c\u6307\u5b9a\u54ea\u4e9b\u8bb0\u5f55\u5c06\u88ab\u66f4\u65b0\u3002<\/li>\n<\/ul>\n<p><strong>\u66f4\u65b0\u8bb0\u5f55\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u786e\u5b9a\u8981\u66f4\u65b0\u7684\u8868\u548c\u5217\uff1a<\/strong>\u9996\u5148\uff0c\u786e\u5b9a\u8981\u66f4\u65b0\u7684\u8868\u548c\u8981\u66f4\u65b0\u7684\u7279\u5b9a\u5217\u3002<\/li>\n<li> <strong>\u6307\u5b9a\u66f4\u65b0\u503c\uff1a<\/strong>\u6307\u5b9a\u8981\u66f4\u65b0\u7684\u6bcf\u4e2a\u5217\u7684\u65b0\u503c\u3002<\/li>\n<li> <strong>\u6dfb\u52a0 WHERE \u5b50\u53e5\uff1a<\/strong>WHERE \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a\u8981\u66f4\u65b0\u54ea\u4e9b\u8bb0\u5f55\u3002\u53ef\u4ee5\u4f7f\u7528\u76f8\u7b49\u6027\u6bd4\u8f83\uff08=\uff09\u3001\u4e0d\u76f8\u7b49\u6027\u6bd4\u8f83\uff08\uff09\u3001\u8303\u56f4\u6bd4\u8f83\uff08BETWEEN\uff09\u3001IN \u64cd\u4f5c\u7b26\u548c LIKE \u64cd\u4f5c\u7b26\u6765\u521b\u5efa\u6761\u4ef6\u3002<\/li>\n<li> <strong>\u6267\u884c UPDATE \u8bed\u53e5\uff1a<\/strong>\u4e00\u65e6\u6307\u5b9a\u4e86\u6240\u6709\u53c2\u6570\uff0c\u5c31\u53ef\u4ee5\u6267\u884c UPDATE \u8bed\u53e5\u4ee5\u66f4\u65b0\u8bb0\u5f55\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u8981\u5c06 &#8220;customers&#8221; \u8868\u4e2d\u5ba2\u6237 ID \u4e3a 1 \u7684\u5ba2\u6237\u59d3\u540d\u66f4\u65b0\u4e3a &#8220;John Doe&#8221;\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>UPDATE customers\nSET name = 'John Doe'\nWHERE customer_id = 1;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6267\u884c\u6b64\u8bed\u53e5\u540e\uff0c\u5ba2\u6237 ID \u4e3a 1 \u7684\u8bb0\u5f55\u7684 &#8220;name&#8221; \u5217\u5c06\u66f4\u65b0\u4e3a &#8220;John Doe&#8221;\u3002<\/p>\n<p><strong>\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>UPDATE \u8bed\u53e5\u53ef\u4ee5\u66f4\u65b0\u591a\u4e2a\u5217\uff0c\u53ea\u9700\u5728 SET \u5b50\u53e5\u4e2d\u5217\u51fa\u5b83\u4eec\u5373\u53ef\u3002<\/li>\n<li>WHERE \u5b50\u53e5\u662f\u53ef\u9009\u7684\uff0c\u5982\u679c\u6ca1\u6709\u6307\u5b9a\uff0c\u5219\u4f1a\u66f4\u65b0\u8868\u4e2d\u7684\u6240\u6709\u8bb0\u5f55\u3002<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528 SQL \u7684\u4e8b\u52a1\u673a\u5236\u6765\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u4f7f\u7528update\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 update \u8bed\u53e5\u7528\u4e8e\u66f4\u65b0\u73b0\u6709\u8bb0\u5f55\uff0c\u8bed\u6cd5\u4e3a\uff1aupdate table_name set column1 = value1, &#8230; where condition\u3002\u5176\u6b65\u9aa4\u5305\u62ec\uff1a\u786e\u5b9a\u8868\u548c\u5217\u3002\u6307\u5b9a\u66f4\u65b0\u503c\u3002\u6dfb\u52a0 where \u5b50\u53e5\u6307\u5b9a\u66f4\u65b0\u6761\u4ef6\u3002\u6267\u884c update \u8bed\u53e5\u4ee5\u66f4\u65b0\u8bb0\u5f55\u3002 MySQL UPDATE \u8bed\u53e5 \u5982\u4f55\u4f7f\u7528 UPDATE \u8bed\u53e5\uff1f UPDATE \u8bed\u53e5\u7528\u4e8e\u66f4\u65b0\u8868\u4e2d\u73b0\u6709\u7684\u8bb0\u5f55\u3002\u5176\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b\uff1a UPDATE table_name SET column1 = value1, column2 = value2, &#8230; WHERE condition; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a table_name\uff1a\u8981\u66f4\u65b0\u7684\u8868\u7684\u540d\u79f0\u3002 column1, column2, &#8230;\uff1a\u8981\u66f4\u65b0\u7684\u5217\u7684\u540d\u79f0\u3002 value1, value2, &#8230;\uff1a\u8981\u66f4\u65b0\u7684\u503c\u3002 condition\uff1a\u66f4\u65b0\u6761\u4ef6\uff0c\u6307\u5b9a\u54ea\u4e9b\u8bb0\u5f55\u5c06\u88ab\u66f4\u65b0\u3002 \u66f4\u65b0\u8bb0\u5f55\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a \u786e\u5b9a\u8981\u66f4\u65b0\u7684\u8868\u548c\u5217\uff1a\u9996\u5148\uff0c\u786e\u5b9a\u8981\u66f4\u65b0\u7684\u8868\u548c\u8981\u66f4\u65b0\u7684\u7279\u5b9a\u5217\u3002 \u6307\u5b9a\u66f4\u65b0\u503c\uff1a\u6307\u5b9a\u8981\u66f4\u65b0\u7684\u6bcf\u4e2a\u5217\u7684\u65b0\u503c\u3002 \u6dfb\u52a0 WHERE \u5b50\u53e5\uff1aWHERE \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a\u8981\u66f4\u65b0\u54ea\u4e9b\u8bb0\u5f55\u3002\u53ef\u4ee5\u4f7f\u7528\u76f8\u7b49\u6027\u6bd4\u8f83\uff08=\uff09\u3001\u4e0d\u76f8\u7b49\u6027\u6bd4\u8f83\uff08\uff09\u3001\u8303\u56f4\u6bd4\u8f83\uff08BETWEEN\uff09\u3001IN \u64cd\u4f5c\u7b26\u548c LIKE \u64cd\u4f5c\u7b26\u6765\u521b\u5efa\u6761\u4ef6\u3002 [&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-5264","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5264","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=5264"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5264\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}