Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 943185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:23:44+00:00 2026-05-15T22:23:44+00:00

Is anyone aware of a T-SQL script that can detect redundant indexes across an

  • 0

Is anyone aware of a T-SQL script that can detect redundant indexes across an entire database? An example of a redundant index in a table would be as follows:

Index 1: 'ColumnA', 'ColumnB', 'ColumnC'
Index 2: 'ColumnA', 'ColumnB'

Ignoring other considerations, such as the width of columns and covering indexes, Index 2 would be redundant.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:23:45+00:00Added an answer on May 15, 2026 at 10:23 pm

    There are situations where the redundancy doesn’t hold. For example, say ColumnC was a huuge field, but you’d sometimes have to retrieve it quickly. Your index 1 would not require a key lookup for:

    select ColumnC from YourTable where ColumnnA = 12
    

    On the other hand index 2 is much smaller, so it can be read in memory for queries that require an index scan:

    select * from YourTable where ColumnnA like '%hello%'
    

    So they’re not really redundant.

    If you’re not convinced by my above argument, you can find “redundant” indexes like:

    ;with ind as (
        select  a.object_id
        ,       a.index_id
        ,       cast(col_list.list as varchar(max)) as list
        from    (
                select  distinct object_id
                ,       index_id
                from    sys.index_columns
                ) a
        cross apply
                (
                select  cast(column_id as varchar(16)) + ',' as [text()]
                from    sys.index_columns b
                where   a.object_id = b.object_id
                        and a.index_id = b.index_id
                for xml path(''), type
                ) col_list (list)
    )
    select  object_name(a.object_id) as TableName
    ,       asi.name as FatherIndex
    ,       bsi.name as RedundantIndex
    from    ind a
    join    sys.sysindexes asi
    on      asi.id = a.object_id
            and asi.indid = a.index_id
    join    ind b
    on      a.object_id = b.object_id
            and a.object_id = b.object_id
            and len(a.list) > len(b.list)
            and left(a.list, LEN(b.list)) = b.list
    join    sys.sysindexes bsi
    on      bsi.id = b.object_id
            and bsi.indid = b.index_id
    

    Bring cake for your users in case performance decreases “unexpectedly” 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is anyone aware of a script/class (preferably in PHP) that would parse a given
Is anyone aware of a reasonably well documented example of simulated annealing in Visual
Is anyone aware of any method (or external plugin) that would allow for nested
Is anyone aware of a free utility, preferably with source code, that will create
This is a long shot, but is anyone aware of any libraries that would
Is anyone aware of a language feature or technique in C++ to prevent a
Is anyone aware of any text editors with Visual Studio editor functionality? Specifically, I'm
Is anyone aware of general UI design guidelines for increasing ad revenue from web
Is anyone aware of a way of sftp'ing from Unix to Windows Thanks Damien
Is anyone aware of any gems, tutorials, or solutions enabling a user to sign

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.