Optimization t-sql query

Posted by phenevo on Stack Overflow See other posts from Stack Overflow or by phenevo
Published on 2010-05-10T13:25:15Z Indexed on 2010/05/17 3:10 UTC
Read the original article Hit count: 277

Filed under:
|

Hi,

I'm newbie in t-sql, and I wonder why this query executes so long ? Is there any way to optimize this ??

update aggregateflags set value=@value where objecttype=@objecttype and objectcode=@objectcode and storagetype=@storagetype and value != 2 and type=@type 
IF @@ROWCOUNT=0 
Select * from aggregateflags where objecttype=@objecttype and objectcode=@objectcode and storagetype=@storagetype and value = 2 and type=@type  
IF @@ROWCOUNT=0  
insert into aggregateflags (objectcode,objecttype,value,type,storagetype) 
select @objectcode,@objecttype,@value,@type,@storagetype

@value int
@storagetype int
@type int
@objectcode nvarchar(100)
@objecttype int

There is not foreign key.

© Stack Overflow or respective owner

Related posts about tsql

Related posts about optimization