Fastest Mass Update

I am attempted to find the quickest way to perform an update of 4-6 million rows in a sql table. Our customers do not have enough disk space to do this update in 1 batch. I have attempted the following while loop while commiting every 100000 updates, but the update still takes hours to perform. Anyone have ideas on how to make this work faster? Any ideas would be greatly appreciated.

declare @oid varchar(13)
declare @count int
set @count = 0
set @optimizeSize = 100000
select @oid = min(foo.object_id) from foo where x = 1
while @oid is not null
update foo wehre foo.object_id = @oid
select @oid = min(foo.object_id) from foo where x = 1 and foo.object_id > @oid
set @count = @count + 1
IF @count = @optimizeSize
commit transaction
set @count = 0


Mass Update In SQL

I have a Hits table that tracks the hits on the id of a Link table:
int linkId (foreign Key to Link)
datetime dateCreated
varchar(50) ip
We recently had to merge Links from different systems that are implemented similarly.  As a result, all the linkIds are now wrong in the Hits table because the ids all changed.  I managed to track down all the old ids and their associated new ids and have it in a table that I call joined_links
joined_linksint oldId
int newId
So, how do I do a mass update of these linkIds in the Hits table in SQL?  I know I could do it in .NET, but I'd rather not write an app to do that runs thousands of update statements.  There's gotta be a way to do it something like this:
UPDATE Hits h SET h.linkId = (SELECT newId FROM joined_links WHERE oldId=h.linkId)
but obviously I don't have visibility of that linkId in the subselect...  A Loop maybe?

View Replies View Related

Mass Update From ASP To SQL 7

I have an ASP form that users enter a store's product qty's into, then update. I have sp in SQL 7 that handles append, insert, update, but I need to give the users an option to mass update many stores at once when they all have the same product qty's. I've never done this. Can someone show me please?

Bruce Wexler

View Replies View Related

Mass Update

This is a run of the mill application that moves orders from one table to another. There are 2 tables, Ordersummary & HstOrders.
Ordersummary has the following columns...
HstOrders has the following columns...
The above two tables are bound by Identifier. After each month end, Orders are moved from Ordersummary to HstOrders.

Now my task is to update all rows in OrderSummary with the order details as seen in HSTOrders for ordertype = 'CREDIT'. OrderReferenceOrigin(in Ordersummary) should be updated with the value of Orderreference(from hstorders).

I have to update each row at a time & I need to write a cursor for mass updates where ordersummary.identifier = hstorders.identifier.

Can someone please help with in writing this update statement as I never wrote a cursor.

View Replies View Related

Is It Possible To Mass Update Stats?

SQL Server 2000 on Win2k

I'm fairly new to SQL Server and I'm just wondering if it's possible to Update Statistice for all indexes somehow? I'm looking at the Update Statistics command and it doesn't seem to be possible.

The situation we have is a reporting DB that basically has all it's tables truncated and remade every night by some DTS jobs that import from another datasource and change the data and build some denormalzed tables etc.
Some of the large Insert operations go from taking 8 mins to taking several hours sometimes and updating the stats seems to fix the problem for a while. So I'd like to make sure the optimizer has all the latest stats for all tables.

Any other advice would be appreciated.


View Replies View Related

Mass Update On Table With Trigger

Hi,I need to update a field in about 20 records on a table. The table hasan update trigger (which updates the [lastedited] field whenever arecord is updated). As a result I'm getting an error: "Subqueryreturned more than 1 value.", and the update fails.Is there a way in the stored procedure to handle this issue?thanks for your help.Paul

View Replies View Related

Why Triggers Don't Fire On Mass Update

If I have a trigger on a field in a table, and I update one record trigger fire properly. If I do a update to that same field on all records in the table the trigger does not fire. I the error in the trigger, or do I need to change my update statement?

View Replies View Related

Fastest/best Way To Handle Update

I have a master table which has demographic data such as name, dob, location along with a primary key id. It will have about 10-12000 records. We get a refresh file every hour which may or may not have corrections for these records hourly with about 3,000 records. I put this data into a table. This data should be considered always to be correct. To handle the update to the master table I need to create an update process. I can take one of two approaches, just update all the records in the master table regardless if they are correct or not, or do some type of left join on those that do not match (in other words, only update the ones where thae names or dob don't match) There is an underlying update trigger on the patient master which will also fire if these values are changed. An opinions on a best approach?

View Replies View Related

Fastest Way To Update 20 + Million Records

What is the fastest way to update 20million records in our database.
I have tried to do a simple update statement like this:
update trail_log with (tablockx, holdlock)
set trail_log .entry_by = users.user_identity
from users
where trail_log.entry_by = users.user_id

but it take 10 plus hours to run since it cannot commit the transactions until the very end. So was was thinking that I need to commit in batch like after 50K but that is slow as well.
Set rowcount 50000
Declare @rc int
Set @rc=50000
While @rc=50000
Begin Transaction
update trail_log With (tablockx, holdlock)
set trail_log.entry_by = users.user_identity
from users
where trail_log.entry_by = users.user_id
and trail_log.entry_by not like '%[0-9]%'
Select @rc=@@rowcount
--Commit the transaction
I have let the above statement run for 1.5 hours and it only update 450000 rows. Any ideas...
Maybe I'm doing it wrong. Please Help!!

View Replies View Related

Mass Insert / Update External Data Into Internal SQL Database

Hola!I'm currently building a site that uses an external database to store all the product details, and an internal database that will act as a cache so that we don't have to keep hitting the external database to retrieve the products every time a customer requests a list.What I need to do is retrieve all these products from External and insert them into Internal if they don't exist - if they do already exist then I have to update Internal with new prices, number in stock etc.I was wondering if there was a way to insert / update these products en-mass without looping through and building a new insert / update query for every product - there could be thousands at a time!Does anyone have any ideas or could you point me in the right direction?I'm thinking that because I need to check if the products exist in a different data store than the original source, I don't have a choice but to loop through them all.Cheers,G. 

View Replies View Related

The Fastest Way To Perform An Update ... Advice Needed :)

Hi all,

I have a situation where my Visual C# application presents a number of fields.  In order to update a student object, I wish to call a stored proc.  1 or more fields can be updated...  And If one is left null, then I don't want to update it, but instead I want to keep the old value.

I am really wondering if I am approaching this the right way.  The following stored proc does what I want it to do, however I'm thinking there may be a faster way...

Here it is:

-- Update a student, by ID.

DROP PROCEDURE p_UpdateStudent



@NewFName VARCHAR(25),

@NewOName VARCHAR(25),

@NewLName VARCHAR(25),


@NewENumber VARCHAR(10),

@NewContactAID INT,

@NewContactBID INT












-- Get all of the old values

SELECT @FName = FName FROM TBL_Student WHERE ID = 10000

SELECT @OName = OName FROM TBL_Student WHERE ID = 10000

SELECT @LName = LName FROM TBL_Student WHERE ID = 10000


SELECT @ENumber = ENumber FROM TBL_Student WHERE ID = 10000

SELECT @ContactAID = ContactAID FROM TBL_Student WHERE ID = 10000

SELECT @ContactBID = ContactBID FROM TBL_Student WHERE ID = 10000

-- USE ISNULL to set all of the new parameters to the provided values only if they are not null

-- Keep the old ones otherwise.

SET @NewFName = ISNULL(@NewFName, @FName)

SET @NewOName = ISNULL(@NewOName, @OName)

SET @NewLName = ISNULL(@NewLName, @LName)


SET @NewENumber = ISNULL(@NewENumber, @ENumber)

SET @NewContactAID = ISNULL(@NewContactAID, @ContactAID)

SET @NewContactBID = ISNULL(@NewContactBID, @ContactBID)

-- Do the update


SET FName = @NewFName,

OName = @NewOName,

LName = @NewLName,

DOB = @NewDOB,

ENumber = @NewENumber,

ContactAID = @NewContactAID,

ContactBID = @NewContactBID


ID = @ID



So yeah it works.  But As you can see I wish to keep an old copy of the values to perform checks pre update....

Is there any faster way, or am I on the right track?  I need a pro's advice :) (before i write all of my procs!!)

Thanks all.






View Replies View Related

Mass DTS Modification

I have a series of DTS packages.
Each package has 20 queries.
Each query has a server name.
Is there a way to change the servername without editing each query in each DTS package.
I'd like to copy the template DTS package, then perform the modification.


View Replies View Related

Mass SQL Inserts - Performance :-(


I have an user table with a single integer column. No indexes, no identities, nothing. I have to insert 600,000 rows via a client app. In tests, using BCP/Bulk Insert/DTS all runs OK (sub 3 seconds). However the app takes 5000 rows a second [considerably slower]. I can mimic this slow perfomance, within DTS, by removing the 'Fast Load' & 'Batch' options.

Question= why would the SQL insert run slower on one server and as fast as BCP/Bulk Insert/DTS on another? What can I check on the 'slow' running server? May there be a file version anomally ??

Version = SQL-2000 SP4

Any help much appreciated !!!

View Replies View Related

Mass Updates In SQL Server

Does anyone know what the best way to do mass updates in SQL server is? I am currently using the methodology suggested in this article

But the article is assuming that once I update a field it is going to have a value that is NOT NULL. So I can loop through and update the rows that have a NOT NULL value. But my updated rows do contain NULL values, in this case what is the best way to go about this???

Here is my code. I want to avoid using Upd_flag becos
after the following code runs I need to reset that flag
before I run my next query

--Set rowcount to 50000 to limit number of inserts per batch
Set rowcount 50000

--Declare variable for row count
Declare @rc int
Set @rc=50000

While @rc=50000

Begin Transaction

--Use tablockx and holdlock to obtain and hold
--an immediate exclusive table lock. This usually
--speeds the insert because only one lock is needed.

update t_PGBA_DTL With (tablockx, holdlock)
SET t_PGBA_DTL.procedur = A.[Proc code],
t_PGBA_DTL.Upd_flag = 1
= A.[Proc code]
WHERE t_PGBA_DTL.Upd_flag = 0

--Get number of rows updated
--Process will continue until less than 50000
Select @rc=@@rowcount

--Commit the transaction

View Replies View Related

Mass Mailing Through SQL Server

Hi friends,
Any idea about mass mailing system using SQL Server .Pls get back to me.
thanx and regards

View Replies View Related


I have the following problem. I need to insert 100.000 records (50Kb each) in one operation from a VB program into a SQL Server 2005 database. All of these records will be ready for inserting at the same time.
How to make this insert as one big transaction instead of 100.000 small ones?

View Replies View Related

How To Best Deploy Mass Packages ???

Hi There
Most of the time my solutions consist of 1 or 2 packages and config files work well.
Now i have a solution with about 50 packages i have to move to QA.
However a config file has the package ID, so even thoug they use the same data source connection. I would have to create and change 50 config files.
Data sources are kept in the package xml , so if i copy all the packages to QA , and then change the Global Data Source connection, i still have to open each package maually and save it again.
Surely there must be an easy way to move all 50 packages and have the connection now point to QA. But config files and global data sources dont do the trick, what am i missing here ?

View Replies View Related

Mass Subscription Email Changes


The company i work for changed names and all email addresses within the company have changed.  While it was OK for a while they are no longer going to be forwarding email to the old addresses to the new ones.  There are Tons of subscriptions and tons of email addresses that need to be changed to the new names.
If i could find the table with the TO: part of the subscription held in it i could just run an update on that field and it would be solved...however, i cannot find that field...
Without going into every subscription in report manager, how can i change the email addresses? Any Suggestions?
Thanks in advance

View Replies View Related

Connection Timing Out When Trying To Do A Mass DTS Process

Here is the error message that I'm reciving:Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. I was wondering if anyone knew how to increase the timeout period.  The DTS package which I'm firing off is farily large and is exceeding the limit of the timout period -- I just need to be able to increase this limit.  Do I do this on my SQL Server or do I do this in my connection property.  Just as a FYI I have my connectionstring set up in my WebConfig file.  Thanks in advanceRB

View Replies View Related

Mass Import To Sql Server Through Vb Style

I am making a prog that needs to import many records from a spreadsheet on a local computer through into sql server
is there a simple command to do this or is there information on how to do this
please give all the information that you can thank you

View Replies View Related

Software For Performing Mass Design Changes


I was wondering if anyone knows of any way, including third party tools, to replicate a design change on a table across many different databases. I have written an ASP script that allows me to copy multiple tables to multiple databases in one go but I need something that will allow me to replicate the design of a table by comparing source and destination tables. So far I have scripted most of it but I have no idea on which system table to get the identity information and it seems there must be an easier way!

Any help would be appreciated,


View Replies View Related

Transaction Log Backups (Mass Storage)

I want to backing up my hourly transaction log backups direct to a mass storage unit as opposed to the local server. However when trying to set this up it only gives me option of backing up to local drives, even though I have a drive mappping to the mass storage unit.. I'm there is a simple around this.Would appreciate any advice..many Thanks..

View Replies View Related

Tempdb Filling Up - Mass Deletes


I've been having problems with my tempdb filling up, and causing all databases on the server to stop functioning properly. I've been removing alot of data lately (millions of rows), and I think this is the reason why my tempdb log is going thru an unusual load.

Whats the best way to make sure the tempdb doesnt fill up causing me major problems? I had temporarily turned off backups while I was having a new HD put in. Am I right in thinking that when a DB is backed up, the tempdb log is reduced in size? Should maintaining a daily backup solution help keep things under control ?

Thanks very much for any tips!


View Replies View Related

What Is The Fastest Way To Do This

right now I have a stored procedure that goes through each of the Line and Body fields using a cursor. The problem is that this method is very slow. How would you experts solve this problem? any Hints or suggestions?






View Replies View Related

Mass Alter Table Fields - Script Help

Hello,I need to alter fields in all my tables of a given database, and Iwould to do this via a t-sql script.Example, I want to change all fields called SESSION_ID to char(6). Thefield is usually varchar(10), but the data is always 6 characters inlength. I have serveral fields that are fixed length that I want tomove from varchar to char.I believe I can find all the tables where the field exists usingselect * from INFORMATION_SCHEMA.columns where column_name ='SESSION_Id'but I dont know how to take this into an ALTER TABLE , ALTER COLUMNthat can be automatedTIARob

View Replies View Related

Sql Slowed To A Crawl After Deleting Mass Rows


I've deleted about 3-4 million rows from one of my tables as the data was old and no longer needed. The problem is that now queries are runnning extra slow. I am in the process of running taras isp_ALTER_INDEX however its taking quite a long time and seems to be slowing things down even further while its running as expected. (It's been running 4 hours already, I have stopped it and will rerun it a slower traffic period for the db server)

Just wondering if I have the right approach here or if anyone else has any suggestions.

Thanks for your help!

View Replies View Related

Mass Table Structure Change For Column Order


Say you have an existing populated SQL 2005 database, with 700+ tables, and you want to just change the order of the columns inside every table.  Short of manually building conversion scripts, anyone know an automated way to do this?  I was thinking thru ways to do them all in one shot, and have tools like Erwin and DbGhost that could be used also.  Basically moving some standard audit columns from the end of the tables to just after the PK columns. 
Thanks, Bruce

View Replies View Related

Copyrights 2005-15, All rights reserved