{"id":5899,"date":"2024-11-14T09:41:48","date_gmt":"2024-11-14T01:41:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5899\/"},"modified":"2024-11-14T09:41:48","modified_gmt":"2024-11-14T01:41:48","slug":"sql%e6%80%8e%e4%b9%88%e5%86%99%e6%9b%b4%e6%96%b0%e8%af%ad%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5899\/","title":{"rendered":"sql\u600e\u4e48\u5199\u66f4\u65b0\u8bed\u53e5"},"content":{"rendered":"<blockquote><p>\n  sql \u4e2d\u7684 update \u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u73b0\u6709\u8bb0\u5f55\uff1a\u8bed\u6cd5\uff1a update table_name set column1 = new_value1, column2 = new_value2, &#8230; where condition\u7528\u6cd5\uff1a\u6307\u5b9a\u8868\u540d\u5728 set \u5b50\u53e5\u4e2d\u5217\u51fa\u8981\u66f4\u65b0\u7684\u5217\u53ca\u65b0\u503c\u4f7f\u7528 where \u5b50\u53e5\u6307\u5b9a\u66f4\u65b0\u6761\u4ef6\uff08\u53ef\u9009\uff09\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/03\/2024060321574573691.jpg\" class=\"aligncenter\" title=\"sql\u600e\u4e48\u5199\u66f4\u65b0\u8bed\u53e5\u63d2\u56fe\" alt=\"sql\u600e\u4e48\u5199\u66f4\u65b0\u8bed\u53e5\u63d2\u56fe\" \/><\/p>\n<p><strong>SQL \u66f4\u65b0\u8bed\u53e5\uff1a\u8bed\u6cd5\u548c\u7528\u6cd5<\/strong><\/p>\n<p>\u5728 SQL \u4e2d\uff0cUPDATE \u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u6570\u636e\u5e93\u8868\u4e2d\u73b0\u6709\u7684\u8bb0\u5f55\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>\u89e3\u91ca\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>table_name\uff1a<\/strong>\u8981\u66f4\u65b0\u7684\u8868\u540d\u3002<\/li>\n<li> <strong>SET\uff1a<\/strong>\u6307\u5b9a\u8981\u66f4\u65b0\u7684\u5217\u53ca\u5176\u65b0\u503c\u3002<\/li>\n<li> <strong>condition\uff1a<\/strong>\u4e00\u4e2a\u53ef\u9009\u6761\u4ef6\uff0c\u7528\u4e8e\u6307\u5b9a\u8981\u66f4\u65b0\u7684\u7279\u5b9a\u8bb0\u5f55\u3002<\/li>\n<\/ul>\n<p><strong>\u7528\u6cd5\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u786e\u5b9a\u8981\u66f4\u65b0\u7684\u8868\uff1a<\/strong>\u6307\u5b9a\u8981\u66f4\u65b0\u8bb0\u5f55\u6240\u5728\u7684\u8868\u540d\u3002<\/li>\n<li> <strong>\u6307\u5b9a\u8981\u66f4\u65b0\u7684\u5217\uff1a<\/strong>\u5728 SET \u5b50\u53e5\u4e2d\u5217\u51fa\u8981\u66f4\u65b0\u7684\u5217\uff0c\u5e76\u4e3a\u5b83\u4eec\u5206\u914d\u65b0\u7684\u503c\u3002<\/li>\n<li> <strong>\u6dfb\u52a0\u6761\u4ef6\uff08\u53ef\u9009\uff09\uff1a<\/strong>\u4f7f\u7528 WHERE \u5b50\u53e5\u6307\u5b9a\u7b5b\u9009\u6761\u4ef6\uff0c\u8be5\u6761\u4ef6\u7528\u4e8e\u786e\u5b9a\u8981\u66f4\u65b0\u7684\u7279\u5b9a\u8bb0\u5f55\u3002\u5982\u679c\u6ca1\u6709\u6761\u4ef6\uff0c\u5c06\u66f4\u65b0\u8868\u4e2d\u7684\u6240\u6709\u8bb0\u5f55\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u8981\u66f4\u65b0 students \u8868\u4e2d name \u5217\u4e3a &#8220;John&#8221;\uff0c\u5176\u4e2d id \u5217\u4e3a 1\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>UPDATE students\nSET name = 'John'\nWHERE id = 1;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8981\u66f4\u65b0 users \u8868\u4e2d\u6240\u6709 age \u5927\u4e8e 30 \u7684\u8bb0\u5f55\uff0c\u5c06\u5176 age \u5217\u52a0 1\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>UPDATE users\nSET age = age + 1\nWHERE age &gt; 30;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u6307\u5b9a\u8981\u66f4\u65b0\u7684\u5217\u540d\u62fc\u5199\u6b63\u786e\u3002<\/li>\n<li>\u786e\u4fdd\u65b0\u503c\u4e0e\u5217\u7684\u6570\u636e\u7c7b\u578b\u517c\u5bb9\u3002<\/li>\n<li>\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u6761\u4ef6\uff0c\u5c06\u66f4\u65b0\u8868\u4e2d\u7684\u6240\u6709\u8bb0\u5f55\u3002<\/li>\n<li>\u5728\u4fee\u6539\u4e4b\u524d\uff0c\u8bf7\u52a1\u5fc5\u8fdb\u884c\u6570\u636e\u5907\u4efd\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u600e\u4e48\u5199\u66f4\u65b0\u8bed\u53e5\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>sql \u4e2d\u7684 update \u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u73b0\u6709\u8bb0\u5f55\uff1a\u8bed\u6cd5\uff1a update table_name set column1 = new_value1, column2 = new_value2, &#8230; where condition\u7528\u6cd5\uff1a\u6307\u5b9a\u8868\u540d\u5728 set \u5b50\u53e5\u4e2d\u5217\u51fa\u8981\u66f4\u65b0\u7684\u5217\u53ca\u65b0\u503c\u4f7f\u7528 where \u5b50\u53e5\u6307\u5b9a\u66f4\u65b0\u6761\u4ef6\uff08\u53ef\u9009\uff09 SQL \u66f4\u65b0\u8bed\u53e5\uff1a\u8bed\u6cd5\u548c\u7528\u6cd5 \u5728 SQL \u4e2d\uff0cUPDATE \u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u6570\u636e\u5e93\u8868\u4e2d\u73b0\u6709\u7684\u8bb0\u5f55\u3002 \u8bed\u6cd5\uff1a UPDATE table_name SET column1 = new_value1, column2 = new_value2, &#8230; WHERE condition \u767b\u5f55\u540e\u590d\u5236 \u89e3\u91ca\uff1a table_name\uff1a\u8981\u66f4\u65b0\u7684\u8868\u540d\u3002 SET\uff1a\u6307\u5b9a\u8981\u66f4\u65b0\u7684\u5217\u53ca\u5176\u65b0\u503c\u3002 condition\uff1a\u4e00\u4e2a\u53ef\u9009\u6761\u4ef6\uff0c\u7528\u4e8e\u6307\u5b9a\u8981\u66f4\u65b0\u7684\u7279\u5b9a\u8bb0\u5f55\u3002 \u7528\u6cd5\uff1a \u786e\u5b9a\u8981\u66f4\u65b0\u7684\u8868\uff1a\u6307\u5b9a\u8981\u66f4\u65b0\u8bb0\u5f55\u6240\u5728\u7684\u8868\u540d\u3002 \u6307\u5b9a\u8981\u66f4\u65b0\u7684\u5217\uff1a\u5728 SET \u5b50\u53e5\u4e2d\u5217\u51fa\u8981\u66f4\u65b0\u7684\u5217\uff0c\u5e76\u4e3a\u5b83\u4eec\u5206\u914d\u65b0\u7684\u503c\u3002 \u6dfb\u52a0\u6761\u4ef6\uff08\u53ef\u9009\uff09\uff1a\u4f7f\u7528 WHERE \u5b50\u53e5\u6307\u5b9a\u7b5b\u9009\u6761\u4ef6\uff0c\u8be5\u6761\u4ef6\u7528\u4e8e\u786e\u5b9a\u8981\u66f4\u65b0\u7684\u7279\u5b9a\u8bb0\u5f55\u3002\u5982\u679c\u6ca1\u6709\u6761\u4ef6\uff0c\u5c06\u66f4\u65b0\u8868\u4e2d\u7684\u6240\u6709\u8bb0\u5f55\u3002 \u793a\u4f8b\uff1a \u8981\u66f4\u65b0 students [&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-5899","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5899","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=5899"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5899\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}