473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Updating a large table: set @@rowcount versus explicit transactions

When I need to perform an update against multi-million row table I
typically specify @@rowcount, to reduce locks.

e.g.
set @@rowcount 1000
while exists (select * from myTable where col2 is null)
update myTable
set col2 = col1 + 'blahblah'
where col2 is null

However, my boss' script does something like this. I think it works OK
but it seems overly complicated to me. Any thoughts?

while exists (....)
begin tran

insert into #table
select ...

update myTable
set ...
from myTable join #table ...

(@numberOfRows is a counter variable, tracking #rows that have been
updated since last batch)

if @numberOfRows > 1000
begin
commit
begin tran
end

end

Jul 23 '05 #1
2 7426
I would prefer:

SET ROWCOUNT 1000

WHILE 1=1
BEGIN
UPDATE myTable
SET col2 = col1 + 'blahblah'
WHERE col2 IS NULL
IF @@ROWCOUNT = 0 BREAK
END

Although a batch size of 1000 seems a bit small for multi-million row table.

I don't see any advantages of the temp table version.

--
David Portas
SQL Server MVP
--
Jul 23 '05 #2
Cool. That's even more efficient. Thanks David.

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Antonio Delgado | last post by:
I was wondering if anybody could help me out a little. My goal is to update some information about a system every 2-5 seconds. The information needs to be displayed in some sort of table, but the...
1
by: Good Man | last post by:
Hi there I'm developing a large web application. Part of this web application will be storing numerical chart data in a MySQL table - these numbers will be already calculated, and are just being...
8
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run...
7
by: Bing Wu | last post by:
Hi Folks, I have a very large table containing 170 million rows of coordinats: CREATE TABLE "DB2ADMIN"."COORDINATE" ( "FID" INTEGER NOT NULL , "AID" INTEGER NOT NULL , "X" REAL NOT NULL ,...
0
by: loloxi | last post by:
please i nedd help about updating a table from a form, i hvae a textbox which when it gets an input and saved, i want it to replace the corrseponding field in the table. thanks - hope this makes...
6
by: Hevan | last post by:
Hi, I am using this sql for updating a large table. This sql should update a record like 'abc123'. The first select will return 'abc' and the second select will return '123'. This works fine...
10
by: help4me | last post by:
I am having trouble updating a table. The logic seems so simple but I just can’t get it to work. The table is named test. The column names are passcode, name, address, city, state, zip and email....
2
tdw
by: tdw | last post by:
Hi all, I have several ideas on how to do this, but am having difficulty putting the ideas together and figuring out the most efficient way to do this. I have a database of survey coordinate...
1
oranoos3000
by: oranoos3000 | last post by:
hi I have a table with large height and inside of this large table i have only one table with small height in show small height table is shown in middle of space of large table and have...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.