Click here to Skip to main content
16,017,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 huge tables in my tables each with nearly 12lakhs rows. Product table and Member table.
I need to update a column ActionCd in Product table based on the column Code in Member table

If Product.Code = Member.Code, then Product.ActionCd = 'A'
If Product.Code != Member.Code, then Product.ActionCd = 'P'

I use the following query to update the table

UPDATE Product
SET ActionCd='A'
FROM Product p join Member m on p.Code = m.Code
WHERE p.ActionCd is null

But this query is taking too long to execute - more than an hour. It is because of the huge data in the 2 tables.
How can I reduce the time for the query execution?

I dont know much about indexing in sql. Will the use of indexing help me reduce the time? If so, please explain how to use indexing in this situation.

Thanks in advance.
Posted
Updated 6-Mar-13 23:51pm
v2
Comments
phil.o 7-Mar-13 5:42am    
If Product.Code = Member.Code, then Product.ActionCd = 'A'
If Product.Code = Member.Code, then Product.ActionCd = 'P'

Both these statements are mutually exclusive.

No..Indexing will not reduce the time for updating.It will be helpfull for Searching that to for selecting.
 
Share this answer
 
Comments
SruthiR 7-Mar-13 6:26am    
thanks .. is there any way to reduce the time..
Try this query in testing server

It will reduce the update time

SQL
Update Product set actioncid='A'
from
(
SELECT code from Member
)tmp
where product.code=tmp.product
and product.actioncd is null
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900