Original: Deletes all indexes of the specified table, including primary key index, unique index, and normal index, for SQL Server 2005,
--Delete all indexes in the specified table--usage: DECLARE @tableName varchar--set @tableName = ' table name '-The table name, replacing--exec Sp_dropindex according to the actual situation @tableNameif Exists (select 1 from sysobjects where id = object_id (' Dropindex ') and xtype = ' P ') drop procedure Dropindex gocreate Proce Dure dropindex @tableName varchar (=null)--table name Asif @tableName is null begin RAISERROR (' must provide @tablename parameter ', 12,1) return Endcreate table # (ID int identity, index_name varchar (), index_description varchar (+), Index_keys varchar (100) ) Insert # (Index_name,index_description,index_keys) exec sp_helpindex @tableNamedeclare @i intdeclare @sql varchar (100) Set @i = 1while @i<= (select Max (ID) from #) BEGIN if exists (select 1 from sysobjects A join # B on A.name=b.index_name where [email protected] and A.xtype in (' PK ', ' UQ ')) begin select @sql = ' ALTER TABLE ' + @tableName + ' drop constr Aint ' + (select Index_name from # where id = @i) end ELSE BEGIN Select @sql = ' Drop index ' + @tableName + '. ' + (sel ECT index_name from # WHERE [emAil protected]) End--Print (@sql) exec (@sql) Set @[email protected]+1 enddrop table #go
Execute the preceding SQL statement before executing this stored procedure.
--Delete Index declare @tableName varchar set @tableName = ' table '-the name of the table, replacing the exec Dropindex according to the actual situation @tableNameGO
Deletes all indexes of the specified table, including primary key indexes, unique indexes, and normal indexes, for SQL Server 2005,