i have to find existence of an index and stats.

rajesh yadav 171 Reputation points
2021-08-20T05:27:45.98+00:00

hi,

is there any better way to find the existence of an index or stats then pls tell me.

IF NOT EXISTS (SELECT 1
FROM sys.indexes I
WHERE I.Name = 'XI_Status_Abb_ListDom' -- Index name
AND I.object_id = OBJECT_ID('ListDomain'))

IF NOT EXISTS ( SELECT * FROM sys.stats
WHERE name = 'stat_PipePipeIdParentPipeIdStatusLength'
AND object_ID = OBJECT_ID ('Pipe'))

yours sincerely

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,492 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,707 questions
0 comments No comments
{count} votes

Accepted answer
  1. Olaf Helper 47,416 Reputation points
    2021-08-20T05:56:18.34+00:00

    That's already the right way.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Seeya Xi-MSFT 16,586 Reputation points
    2021-08-20T07:28:57.643+00:00

    Hi @rajesh yadav ,

    The following method cannot be better and detailed, but it can be used for your reference.
    Use sp_helpindex

    Best regards,
    Seeya


    If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.