{"id":66155,"date":"2024-10-14T15:01:15","date_gmt":"2024-10-14T07:01:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/66155\/"},"modified":"2024-10-14T15:01:15","modified_gmt":"2024-10-14T07:01:15","slug":"mssql%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e6%9b%b4%e6%96%b0%e6%93%8d%e4%bd%9c%ef%bc%88mssql-update%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/66155\/","title":{"rendered":"MSSQL\u6578\u64da\u5eab\u7684\u66f4\u65b0\u64cd\u4f5c\uff08mssql update\uff09"},"content":{"rendered":"<h1 id=\"mssql%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e6%9b%b4%e6%96%b0%e6%93%8d%e4%bd%9c%ef%bc%88mssql-update%ef%bc%89-GXdaWKRjfE\">MSSQL\u6578\u64da\u5eab\u7684\u66f4\u65b0\u64cd\u4f5c\uff08mssql update\uff09<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0c\u66f4\u65b0\u64cd\u4f5c\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u74b0\u3002\u5c0d\u65bc\u4f7f\u7528Microsoft SQL Server\uff08MSSQL\uff09\u7684\u958b\u767c\u8005\u548c\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u4f86\u8aaa\uff0c\u4e86\u89e3\u5982\u4f55\u6b63\u78ba\u5730\u57f7\u884c\u66f4\u65b0\u64cd\u4f5c\u662f\u78ba\u4fdd\u6578\u64da\u6e96\u78ba\u6027\u548c\u4e00\u81f4\u6027\u7684\u95dc\u9375\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eMSSQL\u7684\u66f4\u65b0\u64cd\u4f5c\uff0c\u5305\u62ec\u57fa\u672c\u8a9e\u6cd5\u3001\u5e38\u898b\u7528\u6cd5\u53ca\u6ce8\u610f\u4e8b\u9805\u3002<\/p>\n<h2 id=\"%e5%9f%ba%e6%9c%ac%e8%aa%9e%e6%b3%95-GXdaWKRjfE\">\u57fa\u672c\u8a9e\u6cd5<\/h2>\n<p>MSSQL\u7684\u66f4\u65b0\u64cd\u4f5c\u4e3b\u8981\u4f7f\u7528<strong>UPDATE<\/strong>\u8a9e\u53e5\u3002\u5176\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>UPDATE \u8868\u540d\nSET \u5217\u540d1 = \u65b0\u503c1, \u5217\u540d2 = \u65b0\u503c2, ...\nWHERE \u689d\u4ef6;<\/code><\/pre>\n<p>\u5728\u9019\u88e1\uff0c<strong>\u8868\u540d<\/strong>\u662f\u8981\u66f4\u65b0\u7684\u6578\u64da\u8868\uff0c<strong>\u5217\u540d<\/strong>\u662f\u9700\u8981\u66f4\u65b0\u7684\u5b57\u6bb5\uff0c\u800c<strong>\u689d\u4ef6<\/strong>\u5247\u7528\u65bc\u6307\u5b9a\u54ea\u4e9b\u8a18\u9304\u9700\u8981\u88ab\u66f4\u65b0\u3002\u82e5\u4e0d\u52a0\u4e0a<strong>WHERE<\/strong>\u689d\u4ef6\uff0c\u5247\u6240\u6709\u8a18\u9304\u90fd\u6703\u88ab\u66f4\u65b0\uff0c\u9019\u901a\u5e38\u4e0d\u662f\u6211\u5011\u6240\u671f\u671b\u7684\u7d50\u679c\u3002<\/p>\n<h2 id=\"%e7%af%84%e4%be%8b-GXdaWKRjfE\">\u7bc4\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7bc4\u4f8b\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u540d\u70ba<strong>Employees<\/strong>\u7684\u8868\uff0c\u5305\u542b\u54e1\u5de5\u7684\u59d3\u540d\u548c\u85aa\u6c34\u3002\u6211\u5011\u5e0c\u671b\u5c07\u67d0\u4f4d\u54e1\u5de5\u7684\u85aa\u6c34\u66f4\u65b0\u70ba\u65b0\u7684\u6578\u503c\uff1a<\/p>\n<pre><code>UPDATE Employees\nSET Salary = 60000\nWHERE Name = 'John Doe';<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u53ea\u6709\u59d3\u540d\u70ba<strong>John Doe<\/strong>\u7684\u54e1\u5de5\u85aa\u6c34\u6703\u88ab\u66f4\u65b0\u70ba60000\u3002<\/p>\n<h2 id=\"%e5%a4%9a%e5%88%97%e6%9b%b4%e6%96%b0-GXdaWKRjfE\">\u591a\u5217\u66f4\u65b0<\/h2>\n<p>\u5982\u679c\u9700\u8981\u540c\u6642\u66f4\u65b0\u591a\u500b\u5217\uff0c\u53ef\u4ee5\u5728<strong>SET<\/strong>\u5b50\u53e5\u4e2d\u5217\u51fa\u591a\u500b\u5217\u540d\u53ca\u5176\u65b0\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>UPDATE Employees\nSET Salary = 65000, Position = 'Senior Developer'\nWHERE Name = 'Jane Smith';<\/code><\/pre>\n<p>\u9019\u6a23\uff0c\u59d3\u540d\u70ba<strong>Jane Smith<\/strong>\u7684\u54e1\u5de5\u7684\u85aa\u6c34\u548c\u8077\u4f4d\u90fd\u6703\u88ab\u66f4\u65b0\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e5%ad%90%e6%9f%a5%e8%a9%a2%e6%9b%b4%e6%96%b0-GXdaWKRjfE\">\u4f7f\u7528\u5b50\u67e5\u8a62\u66f4\u65b0<\/h2>\n<p>MSSQL\u9084\u652f\u6301\u4f7f\u7528\u5b50\u67e5\u8a62\u4f86\u66f4\u65b0\u6578\u64da\u3002\u9019\u5728\u9700\u8981\u6839\u64da\u5176\u4ed6\u8868\u7684\u6578\u64da\u4f86\u66f4\u65b0\u6642\u7279\u5225\u6709\u7528\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b<strong>Departments<\/strong>\u8868\uff0c\u4e26\u5e0c\u671b\u6839\u64da\u90e8\u9580\u7684\u5e73\u5747\u85aa\u6c34\u4f86\u66f4\u65b0\u54e1\u5de5\u7684\u85aa\u6c34\uff1a<\/p>\n<pre><code>UPDATE Employees\nSET Salary = (SELECT AVG(Salary) FROM Employees WHERE DepartmentID = Employees.DepartmentID)\nWHERE DepartmentID IS NOT NULL;<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u6703\u5c07\u6bcf\u4f4d\u54e1\u5de5\u7684\u85aa\u6c34\u66f4\u65b0\u70ba\u5176\u6240\u5c6c\u90e8\u9580\u7684\u5e73\u5747\u85aa\u6c34\u3002<\/p>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-GXdaWKRjfE\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<ul>\n<li><strong>\u5099\u4efd\u6578\u64da\uff1a<\/strong>\u5728\u57f7\u884c\u66f4\u65b0\u64cd\u4f5c\u4e4b\u524d\uff0c\u5efa\u8b70\u5148\u5099\u4efd\u6578\u64da\uff0c\u4ee5\u9632\u6b62\u610f\u5916\u6578\u64da\u4e1f\u5931\u3002<\/li>\n<li><strong>\u6e2c\u8a66\u66f4\u65b0\uff1a<\/strong>\u5728\u751f\u7522\u74b0\u5883\u4e2d\u57f7\u884c\u66f4\u65b0\u64cd\u4f5c\u4e4b\u524d\uff0c\u6700\u597d\u5728\u6e2c\u8a66\u74b0\u5883\u4e2d\u9032\u884c\u6e2c\u8a66\uff0c\u4ee5\u78ba\u4fdd\u64cd\u4f5c\u7684\u6b63\u78ba\u6027\u3002<\/li>\n<li><strong>\u4f7f\u7528\u4e8b\u52d9\uff1a<\/strong>\u5728\u9032\u884c\u5927\u898f\u6a21\u66f4\u65b0\u6642\uff0c\u4f7f\u7528\u4e8b\u52d9\u53ef\u4ee5\u78ba\u4fdd\u6578\u64da\u7684\u4e00\u81f4\u6027\uff0c\u907f\u514d\u90e8\u5206\u66f4\u65b0\u6210\u529f\u800c\u90e8\u5206\u5931\u6557\u7684\u60c5\u6cc1\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-GXdaWKRjfE\">\u7e3d\u7d50<\/h2>\n<p>MSSQL\u7684\u66f4\u65b0\u64cd\u4f5c\u662f\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u901a\u904e\u6b63\u78ba\u4f7f\u7528<strong>UPDATE<\/strong>\u8a9e\u53e5\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u548c\u7dad\u8b77\u6578\u64da\u7684\u6e96\u78ba\u6027\u3002\u5728\u9032\u884c\u66f4\u65b0\u64cd\u4f5c\u6642\uff0c\u52d9\u5fc5\u6ce8\u610f\u6578\u64da\u7684\u5099\u4efd\u548c\u6e2c\u8a66\uff0c\u4ee5\u78ba\u4fdd\u6578\u64da\u7684\u5b89\u5168\u6027\u548c\u4e00\u81f4\u6027\u3002\u5982\u679c\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u6578\u64da\u7ba1\u7406\u89e3\u6c7a\u65b9\u6848\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u670d\u52d9\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u63d0\u4f9b\u66f4\u7a69\u5b9a\u7684\u74b0\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3MSSQL\u6578\u64da\u5eab\u7684\u66f4\u65b0\u64cd\u4f5c\uff0c\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528UPDATE\u8a9e\u53e5\u6709\u6548\u5730\u4fee\u6539\u6578\u64da\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u6548\u7387\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-66155","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/66155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=66155"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/66155\/revisions"}],"predecessor-version":[{"id":66156,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/66155\/revisions\/66156"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=66155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=66155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=66155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}