Ophaned index

  • I have an entry in the system.indexes table for an index that no longer exists on the table. How can I remove this?

  • Steve Hurst (10/29/2015)


    I have an entry in the system.indexes table for an index that no longer exists on the table. How can I remove this?

    How have you determined that the index no longer exists?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Two things, first the index does not show against the table in SSMS under the Tables (table_name) Indexes. Second, it came to light when running a script to rebuild the index:

    IF EXISTS (SELECT name FROM sys.indexes WHERE name = 'part_needi17')

    DROP INDEX part_needi17 ON part_need

    This fails because the If EXISTS returns True and then the DROP fails.

  • Index names aren't unique across the database. You must have an index called part_needi17 on a different table.

    John

  • Steve Hurst (10/30/2015)


    Two things, first the index does not show against the table in SSMS under the Tables (table_name) Indexes. Second, it came to light when running a script to rebuild the index:

    IF EXISTS (SELECT name FROM sys.indexes WHERE name = 'part_needi17')

    DROP INDEX part_needi17 ON part_need

    This fails because the If EXISTS returns True and then the DROP fails.

    IF EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'part_needi17'

    AND object_id = OBJECT_ID('part_need')

    DROP INDEX part_needi17 ON part_need

    To find out what table the index is associated with:

    SELECT TableName = object_name(object_id), *

    FROM sys.indexes

    WHERE name = 'part_needi17'

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

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

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