游标模版+批量删除表索引

DECLARE @index TABLE(index_name nVARCHAR(max),index_des nVARCHAR(max),index_keys nVARCHAR(max))
INSERT INTO @index
(
	index_name,
	index_des,
	index_keys
)
EXEC sp_helpindex 'ycmis.dbo.费用表'


--游标模版
DECLARE @indexname NVARCHAR(200)
 
DECLARE pcurr       CURSOR  
FOR
    SELECT   index_name
    FROM   @index

OPEN pcurr

FETCH NEXT FROM pcurr INTO @indexname 

WHILE (@@FETCH_STATUS = 0)
BEGIN
 -- PRINT @indexname
 DECLARE @dropindex_sql  VARCHAR(800)
 SET @dropindex_sql ='drop index dbo.费用表.'+@indexname
  EXEC  (@dropindex_sql) 
    ---------------------------- 
    FETCH NEXT FROM pcurr INTO @indexname 
END

CLOSE pcurr

DEALLOCATE pcurr 
 
posted @ 2011-06-25 19:29  qanholas  阅读(441)  评论(0编辑  收藏  举报