Question

  Asked: Feb 28 2008   4:04 PM GMT
  Asked by: Dangagne


Stored Procedure for dropping indexes


Indexes, DROP, Restore, Stored procedures

I would like a stored procedure that will take as input the name of a table.

Whatthe procedure would do is drop all indexes on that table excpet any index that ends with U1 or P1, and save the information on the ones it drops.

Then I would like another strored procedure that takes a table name as input and puts back all the indexes that were dropped.

We need to load 1 to 3 million rows a night and we manually drop all the indexes and put them back after the load. Is this something that can be written as a stored procedure?

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



What database platform are you using?

While this can be done, it is more efficient and much safer to hard code the list of indexes which need to be dropped into a stored procedure, and the same with the create index commands. It requires a little more maintenance when ever indexes are added to the tables, but the end result will be much better.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Database and Storage.

Looking for relevant Database Whitepapers? Visit the SearchOracle.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

Dangagne  |   Mar 3 2008  12:44PM GMT

I am using Microsoft SQL Server 2000, soon to be upgraded to SQL Server 2005

 

Dangagne  |   Mar 3 2008  12:46PM GMT

I don’t even know where the SQL Text is stored for each index so I can retrieve it before actually deleting teh index. When I go into SQL Enterprise and Manage Indexes, I can view thetext, but I have no idea where and how it is stored.