Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Drop and Recreate all indexes

Posted on 2005-05-11
Medium Priority
Last Modified: 2012-08-13
Greetings, Sybase experts!

We have about 320 indexes or so in a particular database that we need to drop and recreate to clear up some space and to make them "clean" again.

We use Embarcadero's RapidSQL, and what we normally would do is to execute the code that drops and creates each index. But with 320 or so of these, it takes some time. What I'd like to be able to do is to create a stored proc that has the code to drop and recreate all 320 indexes, so we don't have to execute each one by one.

We need to repeat this every couple months or so, so having the code all in one place will be helpful going forward.

Isn't the code stored in a table somewhere? Couldn't I do a select that will dump the index drop and creation code for each index in the database and spool the results, which I could then copy and paste in a new stored proc?

If so, what would the query be? If not, is there any way to do this other than manually copying each code and pasting it into a text file?


Question by:jdrits
  • 2
LVL 24

Accepted Solution

Joe Woodhouse earned 2000 total points
ID: 13979386
The "code" per se isn't stored in any system table (unlike for stored procedures and views, where the source code is available), although in principle it can be reverse engineered (which is exactly what RapidSQL and other similar tools do). It's really up to the reverse-engineering code as to whether you get one script per index, one per table, or just one script overall.

There are any number of ways of doing what you want, but before I discuss them, I should point out that if your Sybase is ASE 11.9.2 or above, and your tables use any of the "data-only locking schemes" (datarows or datapages locking), the "reorg rebuild" command achieves the same results but is faster and doesn't need the same amount of free space as drop & recreate index.

I should also say in case you didn't know that you should always drop & recreate the clustered index first on any table - and often that's all you need to do, as recreating a clustered index rebuilds all non-clustered indexes on that table anyway.

But in answer to your specific question, one simple approach is to stick with your current method and build a wrapper script that calls every individual script. You lose a little bit of overhead to connecting, logging in and parsing per index rather than once overall, but given most "create index" commands aren't superfast anyway, this won't cost you all that much.

Another approach is to change the tool you use to one that's more friendly with its output. I'm very impressed with David Owen's "dbschema.pl" which is a platform-independent Perl-based script, available at


It has options to do exactly what you want - output all drop & recreate indexes into a single script.

It requires a build of Perl and Michael Peppler's "sybperl" libraries (also linked to from the page given above). It isn't a pretty GUI like RapidSQL, DBArtisan etc, but it's probably the most powerful & flexible available.

Even Sybase's built-in ASE plugin for Sybase Central can reverse engineer objects and databases, but again I think you don't get all indexes separated out in their own script.

Good luck!

Author Comment

ID: 13980266
Thanks, Joe! We actually found a way with the RapidSQL tool to do it, but you've given us some other useful information as well.

Many thanks!

LVL 24

Expert Comment

by:Joe Woodhouse
ID: 13981076
Good on you for figuring it out anyway. Glad I could add something useful!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Conducting a customer service survey used to be as straightforward as sending a template email out using checkboxes and numerical rating systems to measure satisfaction.
The article explains the process to deploy a Self-Service password reset portal I developed a few years ago. Hopefully, it will prove useful to someone.  Any comments, bug reports etc. are welcome...
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

577 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