|
sql
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to do bulk update in SQL Server 2005.
Hi all,
Let’s say I have a series of updates, each one having a where clause that matches exactly one row. However, if you think about the updates as a group, they form a single logical operation. Is there some way to do a “bulk update†that makes this operation more efficient? Other than repeatedly calling a stored procedure, how can I do this, my goals being to make the operation faster and reduce time during which the table is locked. Thanks. Chen Chen,
You can do it with a CASE expression in the SET clause: UPDATE fb SET fb.DataColumn = CASE WHEN «KeyCondidtion1» THEN «DataExpression1» WHEN «KeyCondidtion2» THEN «DataExpression2» ... WHEN «KeyCondidtionN» THEN «DataExpressionN» END FROM dbo.FooBar fb WHERE («KeyCondidtion1») OR («KeyCondidtion2») .... OR («KeyCondidtionN») Show quoteHide quote "Chen" <C***@discussions.microsoft.com> wrote in message news:FF33D56E-5DC1-4D25-AE1F-2692605174EF@microsoft.com... > Hi all, > > Let's say I have a series of updates, each one having a where clause that > matches exactly one row. > > However, if you think about the updates as a group, they form a single > logical operation. > > Is there some way to do a "bulk update" that makes this operation more > efficient? > > Other than repeatedly calling a stored procedure, how can I do this, my > goals being to make the operation faster and reduce time during which the > table is locked. > > Thanks. > Chen
Other interesting topics
Server Disk Space
Max server memory being ignored Re-attaching database Consolidate datafiles to one drive SQL 2k5-32bit >SQL 2k5-64bit Taking database offline taking long time Maintenence Cleanup Task does not delete backup files 32 vs 64 bit SQL Server hotfixes Bug or Bad Practice on my part? Re: Odd Identity Behavior in Enterprise Manager |
|||||||||||||||||||||||