--Use 'Database' BEGIN TRAN declare @name1 varchar(150) declare @name2 varchar(150) declare CRS Cursor for SELECT OBJECT_NAME(ind.OBJECT_ID) AS DBtable, ind.name AS IndexName FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) indexstats INNER JOIN sys.indexes ind ON ind.object_id = indexstats.object_id AND ind.index_id = indexstats.index_id WHERE indexstats.avg_fragmentation_in_percent > 10 and ind.name is not null ORDER BY indexstats.avg_fragmentation_in_percent DESC; open CRS fetch Next from CRS into @name1,@name2 While (@@FETCH_STATUS=0) begin select @name1 as [Table name],@name2 as [Index name]; ALTER INDEX @name2 ON @name1 REBUILD PARTITION = ALL WITH (fillfactor=85, PAD_INDEX = on, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, ONLINE = on, SORT_IN_TEMPDB = on) fetch next from CRS into @name1,@name2; end close CRS Deallocate CRS ROLLBACK
'with'키워드 근처에서 구문 오류가 발생하는 이유는 무엇입니까?
당신은Dynamic Sql
를 사용할 필요가
Incorrect syntax near the keyword 'with' (for rebuild the indices). If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon
문제점 : –
'with'키워드 근처에 구문이 잘못되었습니다 (색인을 다시 작성하기 위해). 이 문이 공통 테이블 식, xmlnamespaces 절 또는 변경 내용 추적 컨텍스트 절인 경우 이전 문은 세미콜론으로 끝나야합니다. –
추가 정보를 주석에 묻지 말고 추가하십시오. 편집하는 동안 제목을 가지고있는 문제 또는 묻고있는 문제를 설명하는 내용으로 변경하십시오. * 내 문제를 파악하는 데 도움이됩니다 *는 의미가 없으며 검색 결과에서이 사이트의 향후 사용자에게 아무런 가치가 없습니다. 제목은 실제로 도움에 대한 항변이 아닌 질문에 대한 설명을 제공해야합니다. 도움이 필요하다는 것을 알고 있거나 처음에 여기에서 질문하지 않을 것입니다. –