devxlogo

Retrieve All the Index Names for a Given Table Using SQL Query

Use this code to retrieve all the Index names for a given table Using SQL query:

declare @tblName varchar(50);set @tblName = 'GivenTable';SELECT     o.name as TableName, i.name AS IndexNameFROM         sysobjects o, sysindexes iWHERE   (o.id = i.id and o.name = @tblName) AND (i.status = 18450 OR   i.status = 2097152)

i.status = 18450 indicates a clustered index (or, primary key index) in the given table. i.status = 2097152 indicates a non-clustered index in the given table.

Note: @tblName is input parameter to the query. This query is applicable for MS SQL Server 2000.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.