Update multiple columns in SQL(更新 SQL 中的多个列)
问题描述
有没有办法像使用插入语句一样更新 SQL Server 中的多个列?
Is there a way to update multiple columns in SQL server the same way an insert statement is used?
类似:
Update table1 set (a,b,c,d,e,f,g,h,i,j,k)=
(t2.a,t2.b,t2.c,t2.d,t2.e,t2.f,t2.g,t2.h,t2.i,t2.j,t2.k)
from table2 t2
where table1.id=table2.id
或者类似的东西,而不是这样:
Or something like that, rather than like so:
update table set a=t2.a,b=t2.b etc
如果你有 100 多列,写起来可能会很累.
which can be pretty tiresome to write if you have 100+ columns.
推荐答案
烦人的方式"是标准SQL,主流RDBMS是怎么做的.
The "tiresome way" is standard SQL and how mainstream RDBMS do it.
如果有 100 多列,您很可能会遇到设计问题...此外,客户端工具(例如生成 UPDATE 语句)或使用 ORM 也有缓解方法
With a 100+ columns, you mostly likely have a design problem... also, there are mitigating methods in client tools (eg generation UPDATE statements) or by using ORMs
这篇关于更新 SQL 中的多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:更新 SQL 中的多个列


基础教程推荐
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01