Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Need to drop all indexes in SQL 6.5

Posted on 2002-05-29
Medium Priority
Last Modified: 2007-12-19
I am upgrading from SQL Server 6.5 to SQL Server 2000.  I would like to drop all the indexes in the SQL 6.5 database before doing the upgrade.  Is there any way to script this or do it painlessly?
Question by:geowilli
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Accepted Solution

spcmnspff earned 150 total points
ID: 7043056
Here's one I use regularly . . .

CREATE Procedure spDropIndexes

Declare @IndexName VarChar(100)

Declare Indexes CURSOR FOR
SELECT 'dbo.' + '[' + + '].[' + +']'
FROM sysindexes INNER JOIN sysobjects
    ON =
    Inner Join tblTables On = tblTables.TableName
WHERE IndID Not In(0,255) And sysindexes.[Name] Not lIke '_WA_SYS%'

Open Indexes

Fetch Next From Indexes Into @IndexName

While @@Fetch_Status = 0
     Exec('Drop Index ' + @IndexName)
     Fetch Next From Indexes Into @IndexName

Deallocate Indexes

Author Comment

ID: 7043154
I tried the code but it could not find the table 'tblTables'

Author Comment

ID: 7043180
thanks spcmnspff

I got the code to work by making the following alteration to the select statement

SELECT 'dbo.' + '[' + + '].[' + +']'
FROM sysindexes INNER JOIN sysobjects
   ON =
WHERE IndID Not In(0,255) And sysindexes.Name Not lIke '_WA_SYS%'
     and sysobjects.Type = 'U'

Expert Comment

ID: 7043571
Yeah sorry about that, I diidn't edit that query before I put it in there.  In my case I have a table that contains a list of potential tables that I want to drop the indexes on.  If you remove the join to that table you should be fine.  One additional comment regarding this code the not like '_WA_SYS%' refers to an undocumented SQL server feature.  Records in Sysindexes that match this criteria are faux indexes that the optimizer has created to indicate where a potential index is needed.  It means that you have queried this object and a table scan had resulted.  When you use the index tuning wizard it simply does a select in sysindexes for these records and makes the apropriate suggestion.... cool huh?

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question