Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Globally updating a table - need advice

Author  Topic 

katgirl67
Starting Member

4 Posts

Posted - 2001-04-24 : 11:44:15
This may look familiar, as I asked about it a few weeks ago. I need some more advice.

I need some advice as to how to handle a global table update. I've got a product table that contains records obtained from external sources every few weeks. I get the new info in a CSV and need to update the product information with what I get.

Here's the problem: it takes forever to do the update and SQL is timing out. I try to do it in batches, but there are about 200k records, and that is taking a while as well. I need to be able to do this on the hosted web server, and I don't want to bring that down.

Any advice? Is there a faster way to do this? I can't just replace the table -- I need to keep the Product ID the same.

Here's the SProc... any advice is very welcome:

CREATE PROCEDURE [UpdateProductsTable]
(
@StockNumber char(6),
@Source tinyint,
@Artist varchar(30),
@Title varchar(30),
@ProductTypeID tinyint,
@Genre char(3),
@ReleaseDate datetime,
@Price money,
@Status char(2),
@Label char(7),
@Units tinyint
)
AS

If exists (SELECT * FROM tblProducts WHERE StockNumber=@StockNumber AND Source=@Source)
UPDATE tblProducts SET Artist = @Artist,
Title = @Title,
ProductTypeID = @ProductTypeID,
Genre = @Genre,
ReleaseDate = @ReleaseDate,
Price = @Price,
Status = @Status,
Label=@Label,
Units = @Units
WHERE StockNumber = @StockNumber AND Source = @Source

ELSE
INSERT tblProducts
(Artist, Title, ProductTypeID, Genre, ReleaseDate, Price, Status, Label, Units)
VALUES
(@Artist, @Title, @ProductTypeID, @Genre, @ReleaseDate, @Price, @Status, @Label, @Units)

   

- Advertisement -