Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "Could not find any index named [IX_MyIndex]" upon creating it

Tags:

sql-server

I came before this very weird error:

Msg 7999, Level 16, State 9, Line 12 Could not find any index named 'IX_MyIndex' for table 'dbo.MyTable'.

When running the script to create it!!

CREATE NONCLUSTERED INDEX [IX_MyIndex] ON [dbo].[MyTable] (
    [Field1]
    ,[Field2]
    ) INCLUDE (
    Fields3
    ,Fields4
    ,Fields5
    )
    WITH (
         MAXDOP = 4
         ,DATA_COMPRESSION = PAGE
         ,DROP_EXISTING = ON
        )

What am I missing?

like image 579
cnom Avatar asked Feb 13 '19 08:02

cnom


People also ask

Is it possible to search index with name - IX_myindex?

Yes it tries to search index with name - IX_MyIndex which is not available. But after creating index of name IX_MyIndex you can run the same query. Far better to mark Suraj's response as the answer than to post your own. Because that is how SO works.

What happens if I create an index while the database is online?

Previously, modifying the table while an index is being created or dropped typically resulted in a deadlock that cancelled the INSERT, UPDATE, or DELETE statement on the table. "If your using a version greater than 5.1 indices are created while the database is online. So not to worry you won't interrupt production system use."

What happens if I modify the table while an index is created?

Previously, modifying the table while an index is being created or dropped typically resulted in a deadlock that cancelled the INSERT, UPDATE, or DELETE statement on the table.

When does the create index or DROP INDEX statement finish?

The CREATE INDEX or DROP INDEX statement only finishes after all transactions that are accessing the table are completed, so that the initial state of the index reflects the most recent contents of the table.


1 Answers

Remove the last line and execute it.

CREATE NONCLUSTERED INDEX [IX_MyIndex] 
ON [dbo].[MyTable] 
([Field1],[Field2]) 
INCLUDE (Fields3, Fields4, Fields5)

It is trying to search index with name - IX_MyIndex which is not available. But after creating an index of name IX_MyIndex you can run the same query.

like image 109
Suraj Kumar Avatar answered Nov 10 '22 01:11

Suraj Kumar