{"id":6283,"date":"2024-11-14T13:12:23","date_gmt":"2024-11-14T05:12:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6283\/"},"modified":"2024-11-14T13:12:23","modified_gmt":"2024-11-14T05:12:23","slug":"update%e8%af%ad%e5%8f%a5%e5%9c%a8sql%e7%9a%84%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6283\/","title":{"rendered":"update\u8bed\u53e5\u5728SQL\u7684\u7528\u6cd5"},"content":{"rendered":"<blockquote><p>\n  \u5728 sql \u4e2d\uff0cupdate \u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u8868\u4e2d\u73b0\u6709\u8bb0\u5f55\u7684\u7279\u5b9a\u5217\u6216\u884c\u3002\u5b83\u7684\u8bed\u6cd5\u5982\u4e0b\uff1aupdate table_nameset column1 = value1, column2 = value2, &#8230;where condition;\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202407\/02\/2024070201514547798.jpg\" class=\"aligncenter\" title=\"update\u8bed\u53e5\u5728SQL\u7684\u7528\u6cd5\u63d2\u56fe\" alt=\"update\u8bed\u53e5\u5728SQL\u7684\u7528\u6cd5\u63d2\u56fe\" \/><\/p>\n<p><strong>UPDATE \u8bed\u53e5\u5728 SQL \u4e2d\u7684\u7528\u6cd5<\/strong><\/p>\n<p>UPDATE \u8bed\u53e5\u5728 SQL \u4e2d\u7528\u4e8e\u66f4\u65b0\u8868\u4e2d\u73b0\u6709\u7684\u8bb0\u5f55\u3002\u5b83\u5141\u8bb8\u4fee\u6539\u73b0\u6709\u6570\u636e\u7684\u7279\u5b9a\u5217\u6216\u884c\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<pre>UPDATE table_name\nSET column1 = value1, column2 = value2, ...\nWHERE condition;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u53c2\u6570<\/strong><\/p>\n<ul>\n<li> <strong>table_name\uff1a<\/strong>\u8981\u66f4\u65b0\u7684\u8868\u540d\u3002<\/li>\n<li> <strong>column1, column2, &#8230;\uff1a<\/strong>\u8981\u66f4\u65b0\u7684\u5217\u540d\u3002<\/li>\n<li> <strong>value1, value2, &#8230;\uff1a<\/strong>\u8981\u8bbe\u7f6e\u7684\u65b0\u503c\u3002<\/li>\n<li> <strong>WHERE condition\uff1a<\/strong>\u53ef\u9009\u6761\u4ef6\uff0c\u7528\u4e8e\u4ec5\u66f4\u65b0\u7b26\u5408\u6307\u5b9a\u6761\u4ef6\u7684\u884c\u3002<\/li>\n<\/ul>\n<p><strong>\u7528\u6cd5<\/strong><\/p>\n<ol>\n<li><strong>\u66f4\u65b0\u5355\u4e2a\u5217\uff1a<\/strong><\/li>\n<\/ol>\n<pre>UPDATE students\nSET name = 'John Smith'\nWHERE id = 1;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li><strong>\u66f4\u65b0\u591a\u4e2a\u5217\uff1a<\/strong><\/li>\n<\/ol>\n<pre>UPDATE students\nSET name = 'John Smith', age = 25\nWHERE id = 1;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u6761\u4ef6\u66f4\u65b0\uff1a<\/strong><\/li>\n<\/ol>\n<pre>UPDATE students\nSET name = 'John Smith'\nWHERE id = 1 AND age &gt; 20;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li><strong>\u66f4\u65b0\u6240\u6709\u884c\uff1a<\/strong><\/li>\n<\/ol>\n<pre>UPDATE students\nSET name = 'John Smith';<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>UPDATE \u8bed\u53e5\u53ea\u66f4\u65b0\u7b26\u5408 WHERE \u6761\u4ef6\u7684\u884c\u3002<\/li>\n<li>WHERE \u6761\u4ef6\u662f\u53ef\u9009\u7684\uff0c\u5982\u679c\u6ca1\u6709\u6307\u5b9a\uff0c\u5b83\u5c06\u66f4\u65b0\u8868\u4e2d\u7684\u6240\u6709\u884c\u3002<\/li>\n<li>\u5982\u679c\u66f4\u65b0\u7684\u503c\u4e0e\u73b0\u6709\u503c\u76f8\u540c\uff0c\u5219\u4e0d\u4f1a\u8fdb\u884c\u4efb\u4f55\u66f4\u6539\u3002<\/li>\n<li>UPDATE \u8bed\u53e5\u4e0d\u8fd4\u56de\u66f4\u65b0\u7684\u884c\u6570\uff0c\u8981\u83b7\u53d6\u66f4\u65b0\u7684\u884c\u6570\uff0c\u8bf7\u4f7f\u7528 @@ROWCOUNT \u7cfb\u7edf\u53d8\u91cf\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fupdate\u8bed\u53e5\u5728SQL\u7684\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>\u5728 sql \u4e2d\uff0cupdate \u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u8868\u4e2d\u73b0\u6709\u8bb0\u5f55\u7684\u7279\u5b9a\u5217\u6216\u884c\u3002\u5b83\u7684\u8bed\u6cd5\u5982\u4e0b\uff1aupdate table_nameset column1 = value1, column2 = value2, &#8230;where condition; UPDATE \u8bed\u53e5\u5728 SQL \u4e2d\u7684\u7528\u6cd5 UPDATE \u8bed\u53e5\u5728 SQL \u4e2d\u7528\u4e8e\u66f4\u65b0\u8868\u4e2d\u73b0\u6709\u7684\u8bb0\u5f55\u3002\u5b83\u5141\u8bb8\u4fee\u6539\u73b0\u6709\u6570\u636e\u7684\u7279\u5b9a\u5217\u6216\u884c\u3002 \u8bed\u6cd5 UPDATE table_name SET column1 = value1, column2 = value2, &#8230; WHERE condition; \u767b\u5f55\u540e\u590d\u5236 \u53c2\u6570 table_name\uff1a\u8981\u66f4\u65b0\u7684\u8868\u540d\u3002 column1, column2, &#8230;\uff1a\u8981\u66f4\u65b0\u7684\u5217\u540d\u3002 value1, value2, &#8230;\uff1a\u8981\u8bbe\u7f6e\u7684\u65b0\u503c\u3002 WHERE condition\uff1a\u53ef\u9009\u6761\u4ef6\uff0c\u7528\u4e8e\u4ec5\u66f4\u65b0\u7b26\u5408\u6307\u5b9a\u6761\u4ef6\u7684\u884c\u3002 \u7528\u6cd5 \u66f4\u65b0\u5355\u4e2a\u5217\uff1a UPDATE students SET name = &#8216;John Smith&#8217; WHERE [&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-6283","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6283","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=6283"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6283\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}