Solved

How to reduce update time?

Posted on 2011-03-01
4
262 Views
Last Modified: 2012-05-11
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'
0
Comment
Question by:cq27
  • 2
4 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 35014244
first you need to make sure that you have proper indexes on these columns
Product ON igmsi.ISBN, Product.ISBN , Product.Producttype
0
 

Author Comment

by:cq27
ID: 35014401
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
 
LVL 11

Accepted Solution

by:
JoeNuvo earned 125 total points
ID: 35014450
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
 

Author Closing Comment

by:cq27
ID: 35014544
Thanks for the advice and direction. I will have to work out the indexing and try it for myself.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now