[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to reduce update time?

Posted on 2011-03-01
4
Medium Priority
?
277 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 375 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

873 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