SQL : List of all Indexes

By at September 13, 2007 15:30
Filed Under:
WITH    IndexList
          AS ( select   schema_name(sys.objects.schema_id) as SchemaName,
                        sys.objects.[name] as TableName,
                        sys.columns.[name] as ColumnName,
                        Indexes.IndexName as IndexName,
                        Composite = case Indexes.IsComposite
                                      when 0 then 'NO'
                                      when 1 then 'YES'
                                      else 'unknown'
                                    end
               from     sys.objects
                        inner join sys.columns on ( sys.columns.[object_id] = sys.objects.[object_id] )
                        inner join ( select sys.indexes.[name] as IndexName,
                                            IsComposite = case ( select count(*)
                                                                 from   sys.indexes CtrlNdx
                                                                        inner join sys.index_columns CtrlNdxCol on ( CtrlNdxCol.[object_id] = CtrlNdx.[object_id] )
                                                                                                                   and ( CtrlNdxCol.index_id = CtrlNdx.index_id )
                                                                 where  ( CtrlNdx.index_id = sys.indexes.index_id )
                                                                        and ( CtrlNdx.[object_id] = sys.objects.[object_id] )
                                                               )
                                                            when 1 then 0
                                                            else 1
                                                          end,
                                            sys.indexes.[object_id] as [object_id],
                                            sys.index_columns.column_id as column_id
                                     from   sys.indexes
                                            inner join sys.index_columns on ( sys.index_columns.[object_id] = sys.indexes.[object_id] )
                                                                            and ( sys.index_columns.index_id = sys.indexes.index_id )
                                            inner join sys.objects on ( sys.objects.[object_id] = sys.indexes.[object_id] )
                                            inner join sys.columns on ( sys.columns.[object_id] = sys.objects.[object_id] )
                                                                      and ( sys.columns.column_id = sys.index_columns.column_id )
                                   ) Indexes on ( Indexes.[object_id] = sys.objects.[object_id] )
                                                and ( Indexes.column_id = sys.columns.column_id )
               where    ( sys.objects.[type] = 'U' )
                        and ( sys.objects.[name] not in ( 'sysdiagrams' ) )
             )
    SELECT DISTINCT
            tablename,
            indexname
    FROM    IndexList 

Comments

2/26/2010 4:25:09 PM #

Fatcow Review

Should I get a Dedicated Hosting? Right now I am using shared hosting but they keep turning off my websites due to high server overload. Im getting about 4,000 UV a day. What hosting should I get?

Fatcow Review United States | Reply

3/2/2010 2:01:35 PM #

wow mobile

WoW Mobile is awesome! I get free mobile service with t-mobile because I refered 3 people to wow. You can too!

wow mobile United States | Reply

3/20/2010 11:44:08 PM #

cheap prom Dresses

Im getting about 4,000 UV a day. What hosting should I get?

cheap prom Dresses People's Republic of China | Reply

4/27/2010 1:45:38 PM #

How to get ripped

I was looking for this the other day. i dont usually post in blogbut i wanted to say thank you!

How to get ripped United States | Reply

6/2/2010 3:18:12 PM #

how does it work

Brilliant stuff, man!  What you have to say is really important and Im glad you took the time to share it.  What you said really spoke to me and I hope that I can learn more about this.  Thanks for sharing your opinion.  I am yet to find anything as enlightening as this on the web.

how does it work United States | Reply

6/2/2010 11:00:50 PM #

Roofing Contractor Seattle

How is it that just anybody can write a blog and get as popular as this?  Its not like youve said anything incredibly impressive --more like youve painted a pretty picture over an issue that you know nothing about!  I dont want to sound mean, here.  But do you really think that you can get away with adding some pretty pictures and not really say anything?

Roofing Contractor Seattle United States | Reply

6/3/2010 3:36:49 PM #

container gardens

Great job here.  I really enjoyed what you had to say.  Keep going because you definitely bring a new voice to this subject.  Not many people would say what youve said and still make it interesting.  Well, at least Im interested.  Cant wait to see more of this from you.

container gardens United States | Reply

7/6/2010 2:40:08 PM #

Hubert Shirar

Thank you for the awesome info. I look forward to seeing more of such great articles that I could learn an inspiring stuff from!

Hubert Shirar Poland | Reply

8/4/2010 11:27:19 AM #

Amiga

Man, I've been looking all over for this stuff.  Thanks.

Amiga Poland | Reply

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading