且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

根据行中的值用值更新SQL行的最快方法是什么?

更新时间:2023-02-06 18:41:05

我将猜测您正在使用SQL Server.如果是这样,您可以在一个查询中完成所有操作:

I am going to guess that you are using SQL Server. If so, you can do this all in one query:

with toupdate as (
      select p.*,
             row_number() over (partition by fkProductID order by pkProduct) as new_intIssue
      from dbo.tblProducts p
     )
update toupdate
    set intIssue = new_intIssue
    where intIssue <> new_intIssue;