by
0
7
7,196
32
Top 1% !
Popular
Famous
Pearl of Wisdom
Tagged
Specified
OpenSource
Popularity: 829th place
DBMSMS SQL Server
LanguageT-SQL
LicenseMIT_X11
OSWindows

Drop all indexes of a MS SQL Server database

This script removes all the indexes of the currrent database in use
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/12373/Drop-all-indexes-of-a-MS-SQL-Server-data?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
DECLARE idx CURSOR FOR SELECT IDX.name AS idxName, OBJ.name AS tblName FROM sys.indexes IDX inner join sys.all_objects OBJ ON IDX.object_id = OBJ.object_id WHERE (IDX.type) = 2 AND (OBJ.type = 'U') OPEN idx DECLARE @name varchar(200) DECLARE @tablename varchar(200) FETCH NEXT FROM idx INTO @name, @tablename WHILE @@fetch_status = 0 BEGIN EXEC('DROP INDEX ' + @name + ' ON ' + @tablename) FETCH NEXT FROM idx INTO @name, @tablename END CLOSE idx DEALLOCATE idx GO
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus