单个查询中的多个 SQL 更新语句 [英] Multiple SQL Update Statements in single query
问题描述
我现在不得不更新数据库中的大约 12,000 个项目.每行都需要镜像我之前制作的一个 excel 文件.我已经制作了创建每行 SQL 语句的文件,但我不确定是否可以在单个查询中运行每一行.
I am in a situation where I am having to update about 12,000 items in my DB. Each row needs to mirror an excel file that I made previously. I have made the file that creates each line of SQL statement, but I am not sure if I can run each line in a single query.
这是我正在尝试做的一个例子.
This is an example of what I am trying to do.
UPDATE [STORESQL].[dbo].[RPT_ITM_D] SET F1301='1.29' WHERE F01='0000000000001'
UPDATE [STORESQL].[dbo].[RPT_ITM_D] SET F1301='1.39' WHERE F01='0000000000002'
这行得通吗,或者对于我想要实现的目标有更好的选择吗?
Will this work, or are there any better options for what I am trying to achieve?
每个项目都有一个唯一值,要更改的列也将有一个唯一值.我不知道如何使用循环或迄今为止我发现的任何其他方法来完成这项工作.我意识到这可能需要很长时间来处理,但时间不是问题.
Each item will have a unique value and the column to be changed will have a unique value as well. I don't see how I could make this work with a loop, or any other methods I've found so far. I realize that this might take a long time to process, but time is not an issue.
提前致谢
推荐答案
是的,您可以像现在一样在一个查询中添加所有单行更新语句.
Yes, you could add all the single-line-Update-statements in one query like you are doing.
这篇关于单个查询中的多个 SQL 更新语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!