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 2012 Forums
 Transact-SQL (2012)
 Update Statement Taking quite long time.

Author  Topic 

Indsqlbeginner
Starting Member

21 Posts

Posted - 2014-09-29 : 03:28:32
Team,

The update statement is taking very long time to execute. so we have been told to tweak the query. i'd request your help.

Script is below

Update set column1 = '00000' from tbl1 a
where not exists (select id from tbl2 b where a.objid=b.objid) and a.column1 <> '00000'



harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2014-09-29 : 04:03:26
I don't understand the query you have posted.
It is updating column1, which has the value as '00000' to the value of '00000' again. What is the purpose of this query?

Harsh Athalye
http://in.linkedin.com/in/harshathalye/
Go to Top of Page

Indsqlbeginner
Starting Member

21 Posts

Posted - 2014-09-29 : 04:41:41
quote:
Originally posted by harsh_athalye

I don't understand the query you have posted.
It is updating column1, which has the value as '00000' to the value of '00000' again. What is the purpose of this query?

Harsh Athalye
http://in.linkedin.com/in/harshathalye/



Sorry. Now I have updated script accordingly now.

Note : Column1 <> '00000'

can you kindly help now.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2014-09-29 : 05:15:29
You may try converting not exists to left join:


update t1
set column1 = '00000'
from tbl1 t1 left join tbl2 t2 on t1.objid = t2.objid
where t2.objid is null and t1.column1 <> '00000'


Also, you may need to check if any covering index is present on tbl1.

Harsh Athalye
http://in.linkedin.com/in/harshathalye/
Go to Top of Page
   

- Advertisement -