Here is how a highly available database would look. I work on databases with hundreds of thousands of users on databases unconceivable large to most. At my job location, we don't even have a nightly processing time (global app).
Whenever I read posts on this and most other sites, I have to keep in mind that they have a low concurrency of users. As a user base grows, most will have a an increasing number of problems they can't identify over time.
The following code is focused on removing cursors, actually a lot of code should be added for error checking, but for simplicity and keeping to the topic it is left out. While loops in our environment are a necessary evil to keep the number of rows being updated down to a small number so they can complete and release locks within 4 seconds (our apps rule; should actually be lower; perhaps 3). Think availablity first, then speed. At my work location, we even have variations of this that loop through rows in blocks of 5, 10, or whatever higher number still allows us to complete in less than 4 seconds. As you can see, it is a completely different mind set.
Declare @tmp_id int
Declare @prev_id int
Declare @tmp_values varchar(20)
Set LOCK_TIMEOUT = 12000 -- assuming all code in app is tested to have
-- no update take longer than 4 seconds
Set @prev_id = -1 -- assumes all ID's are positive in nature
While Exists (
SELECT TOP 1 @tmp_id = id from DB.dbo.OutPut_tbl WITH(NOLOCK)
Where id > @prev_id -- retrieve next row > than the previous
order by id -- key data ; preferable clustered ;
-- order by id to maintain
-- a reference point
--Direct column pivot into a variable
-- I don't know enough about the column_out field; but lets hope we never
-- increase in size greater than 20; declarations and table field would
-- need to be changed if that
-- was possible.
SELECT @tmp_values = @tmp_values + convert(varchar(20), column_data) + ','
FROM DB.dbo.many_tbl WITH(NOLOCK)
WHERE id = @tmp_id
UPDATE DB.dbo.OutPut_tbl WITH(ROWLOCK) -- assuming that this will take
-- less than 4 seconds
-- otherwise create another
-- while exists loop
SET column_out = Left(@tmp_values,20)
WHERE id = @tmp_id
SET @prev_id = @tmp_id -- move our pointer to the next row
END -- While Exists