我是t-sql的新手,我想知道为什么这个查询执行这么长时间?有没有办法优化这一点?
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没有外键。
发布于 2010-05-10 21:36:47
更容易了解aggregateflags表的结构--列类型和索引。
我会尝试:
如果表aggregateflags上存在与索引匹配的,则返回
UPDATE添加 (如果可以) WITH (ROWLOCK),为SELECT语句添加WITH (NOLOCK) --这有助于避免锁定、编辑或读取数据。将<代码>D20更改为SELECT TOP 1 1 FROM aggregateflags WITH (NOLOCK)... --您不需要数据--您只需检查是否存在行exists.发布于 2010-05-10 21:36:33
确保在列上定义了索引。如果不能解决问题,可以使用SQL studio中的“显示执行计划”按钮,检查出了什么问题。
https://stackoverflow.com/questions/2802922
复制相似问题