Script to list all index in one table

  • How to create a script to input one table name(already indexed) to get list of all index for that table?

  • just a list of indexes, or the scripts for the indexes?

    just the list:

    select * from sys.indexes where object_name(object_id) = 'EDLogDetail'

    scripting the indexes is a little harder, there's a lot of settings to dig for. there's quite a few examples in the scripts section here on SSC:

    http://www.sqlservercentral.com/search/?q=script+indexes&t=s&sort=relevance

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • I ran your script, it list index for that table. I need it.

    Can you tell me how to generate index scripts for one table? I need to apply the scripts for the same table but in another server.

  • adonetok (3/14/2014)


    I ran your script, it list index for that table. I need it.

    Can you tell me how to generate index scripts for one table? I need to apply the scripts for the same table but in another server.

    create a dynamic sql script to iterate through all the tables (in all databases if need be) and insert into a table the location that you want. this is a pretty straight forward thing you want to do actually.

  • if you don't want to browse the scripts section i mentioned, the easiest way is to use SSMS: In SSMS2012, make sure the scripting option for script indexes is true in Tools>>Options>>SQL Server Object Explorer>>Scripting t.

    then just right click the table, choose "Script Table As" and copy and paste the index code generated on the other server.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thank you. It works for me.

Viewing 6 posts - 1 through 5 (of 5 total)

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