Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Erland Sommarskog Newsgroups: comp.databases.ms-sqlserver Subject: Re: trying to replace multiple update statements with one update Date: Tue, 04 Oct 2011 23:14:59 +0200 Organization: Erland Sommarskog Lines: 30 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Injection-Info: mx04.eternal-september.org; posting-host="nBFDv6s1VJQDuF1w6hpX2A"; logging-data="12192"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+CAgnaJaisF7wc/iwW48ft" User-Agent: Xnews/2006.08.24 Mime-proxy/2.1.c.0 (Win32) Cancel-Lock: sha1:dp7w5CtD1KindeR5raNJiH/kPIw= Xref: x330-a1.tempe.blueboxinc.net comp.databases.ms-sqlserver:734 migurus (migurus@yahoo.com) writes: > SQL 2005, there is a table with some 20,000 rows updated quite > frequently, estimates are 2000 updates per minute. Many updates affect > several records at once, so each update touches approximately 10 - 15 > records. > > I am trying to come up with solution that avoids multiple updates with > one update, thinking that it is less load on the db locking etc... The > idea is for the app to declare a variable type of table, populate it > with key - value pairs and then issue one update statement that will > join the in memory table with the table. Sounds like an excellent idea! The only hickup is that SQL 2005 does not support table-valued parameters; you need SQL 2008 for that. However, rather than passing a TVP, you can pass the values in an XML document, and then update the table from that document. See http://www.sommarskog.se/arrays-in-sql-2005.html#XML for an introduction. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Links for SQL Server Books Online: SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx