Scripting out all database table index

  • Hello,

    I have deployed a SQL Server 2000 database with minimum index creation.

    Now I need to ship some new indexes to speed up these database.

    When I use Enterprise Manager to gerenate SQL Script of this database (and enable Index script option) it generates also the Table creation scripts.

    I can run this because the database is running with important data and this script also suppose that all indexes don't exist on the database.

    My question is:

    How can I script ONLY all my Database Indexes script with DROP for existing ones and without drop/create their Tables?

    Regards,

    Fernando.


    Kindest Regards,

    Fernando Malard

  • You can script the indexes one at a time (yawn) in Query Analyser, without getting the tables scripted.  I can't see how you can do this in one step for all indexes in a database, or even for a table.

    On the other hand, going back to the script generated by EM, what about doing a find and replace?  Replace

    'CREATE TABLE' with '/*'

    and replace

    ' [PRIMARY]

    GO' with '*/' (or whatever text always appears at the end of your CREATE TABLE statements)

    and this will comment out all of the CREATE TABLE bits!

    Regards, Phil

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Go to GEnerate SQL script wizard in the EM

    Seelct relevant tables

    click on the formatting tab and uncheck all

    go to options tab and check Indexes

    You will have a nice script to create all the indexes withuot anything else

    don't worry about checking for the existing onesm becasue if they are already existing create index will fail for them but continue for the rest.

     

  • Yeah, that works, good thinking.  Obviously if an index definition has changed, the 'check for existing' is necessary as you'd want to replace the one that's there currently.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply