2010-05-10 3 views
0

저는 t-sql에서 초보자입니다. 왜이 쿼리가 그렇게 오래 실행되는지 궁금합니다. 이 방법을 최적화 할 수 있습니까 ??최적화 t-sql 쿼리

update aggregateflags set [email protected] where [email protected] and [email protected] and [email protected] and value != 2 and [email protected] 
IF @@ROWCOUNT=0 
Select * from aggregateflags where [email protected] and [email protected] and [email protected] and value = 2 and [email protected] 
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 

외래 키가 없습니다.

답변

1

aggregateflags 테이블 - 열 유형 및 인덱스의 구조를 더 쉽게 알 수 있습니다.

나는 시도 할 것이다 :

  1. 확인을 테이블 aggregateflags하는 인덱스가있는 경우. 다른 일치하는 항목을 찾지 못하거나 하나의 일치하는 색인을 만들면 가장 중요한 문제입니다 (executing plan). 편집 또는 읽기 데이터를 잠금 방지하기 도움말 -
  2. hintsWITH (ROWLOCK)UPDATESELECTWITH (NOLOCK) (당신이 할 수있는 경우)를 추가합니다.
  3. 변경 SELECT * FROM aggregateflags... ~ SELECT TOP 1 1 FROM aggregateflags WITH (NOLOCK)... - 데이터가 필요하지 않습니다. 행이 있는지 확인하십시오..
0

열에 인덱스가 정의되어 있는지 확인하십시오. 도움이되지 않으면 SQL Studio에서 "display execution plan"버튼을 사용하여 무엇이 잘못되었는지 확인하십시오.