How to reduce update time?

Hi there,

I have two major tables:
Product Stock Levels = 2.3m rows
Product = 4.2m rows

It takes about 2hr 15 mins to run this Stored Procedure below and complete. I need some assistance to how I can improve this update to be shortened? I understand that JOINS can be written as OUTER AND INNER JOIN OR LEFT JOIN. Can anyone help to clarify?

Thank you.

UPDATE Product SET
StockLevel = 1,
DisabledFlag = 0,
PriceAmt = CAST(igmsi.PublisherPrice AS MONEY)/100,
DiscountPercent=CASE WHEN PriceAmt>14.90 THEN 20 ELSE 15 END
From Stock_update.dbo.Product_Stock_Update igmsi
JOIN Product ON igmsi.ISBN=Product.ISBN
Where Product.Producttype='Books'
cq27Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
JoeNuvoConnect With a Mentor Commented:
regardless of Product Stock keep changing.
in order to make your update query run fast
this should be expecting to have

1. Clustered index of field ISBN on table Product and Product_Stock_Update
2. Index of field ProductType on table Product

if number of rows going to update is just partial of table Product.
above index should help
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
first you need to make sure that you have proper indexes on these columns
Product ON igmsi.ISBN, Product.ISBN , Product.Producttype
0
 
cq27Author Commented:
Hi there,

Will indexing be useful if the Product Stock file keeps changing? I receive a new product file in ASCII txt format daily and I generally will truncate the Product Stock table before inserting the new full data.

I also need some help on how indexing works. Thank you.
0
 
cq27Author Commented:
Thanks for the advice and direction. I will have to work out the indexing and try it for myself.
0
All Courses

From novice to tech pro — start learning today.