SQL: Retrieve a list of Table Indexes

SQL Server contains several Catalog Views that return a wide range of Database Engine data. The Object Views can be used to list, among other things, structural information on database objects.  The following example creates a list of table indexes for SQL Server databases.

-- ##################################################
-- get a list of table indexes
-- ##################################################
 
SELECT 
	ao.object_id AS table_id
	,ao.name AS table_name
	,i.index_id
	,i.is_primary_key
	,i.name AS index_name
FROM
	-- sys.tables can be used to retrieve a list of tables of type 'U'
	sys.all_objects ao LEFT JOIN sys.indexes i 
		ON (ao.object_id = i.object_id)
WHERE 
	(ao.type = N'U')

-- ##################################################