Solved

Need to drop all indexes in SQL 6.5

Posted on 2002-05-29
4
259 Views
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?
0
Comment
Question by:geowilli
[X]
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
4 Comments
 
LVL 5

Accepted Solution

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

CREATE Procedure spDropIndexes
AS

Declare @IndexName VarChar(100)

Declare Indexes CURSOR FOR
SELECT 'dbo.' + '[' + sysobjects.name + '].[' + sysindexes.name +']'
FROM sysindexes INNER JOIN sysobjects
    ON sysindexes.id = sysobjects.id
    Inner Join tblTables On sysobjects.name = 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
Begin
     Exec('Drop Index ' + @IndexName)
     Fetch Next From Indexes Into @IndexName
End

Deallocate Indexes
0
 
LVL 1

Author Comment

by:geowilli
ID: 7043154
I tried the code but it could not find the table 'tblTables'
0
 
LVL 1

Author Comment

by:geowilli
ID: 7043180
thanks spcmnspff

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

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

Expert Comment

by:spcmnspff
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?
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

624 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