Declare @Name varchar(100) Declare @strSql varchar(8000) Declare icursor cursor for select name from sysobjects where xType = 'U' and left(name,1) = 'k'open icursor fetch next from icursor into @Namewhile (@@fetch_status=0) begin set @strSql = 'CREATE CLUSTERED INDEX index_'+@Name+' ON '+@Name+' ([UserID] ASC,[CourseID] ASC) ON [PRIMARY]' exec(@strSql) set @strSql = '' fetch next from icursor into @Name endclose icursor deallocate icursor 没有测试,有问题自行解决。
Declare @strSql varchar(8000) Declare icursor cursor
for
select name from sysobjects where xType = 'U' and left(name,1) = 'k'open icursor
fetch next from icursor into @Namewhile (@@fetch_status=0)
begin
set @strSql = 'CREATE CLUSTERED INDEX index_'+@Name+' ON '+@Name+' ([UserID] ASC,[CourseID] ASC) ON [PRIMARY]'
exec(@strSql)
set @strSql = ''
fetch next from icursor into @Name
endclose icursor
deallocate icursor
没有测试,有问题自行解决。