Skip to content

Instantly share code, notes, and snippets.

@wbhinton
Created December 3, 2019 16:33
Show Gist options
  • Save wbhinton/a25d674474e8f658cd718500b24423fa to your computer and use it in GitHub Desktop.
Save wbhinton/a25d674474e8f658cd718500b24423fa to your computer and use it in GitHub Desktop.
Get a list of tables and their indices
SELECT @@Servername AS ServerName ,
DB_NAME() AS DB_Name ,
o.Name AS TableName ,
i.Name AS IndexName
FROM sys.objects o
INNER JOIN sys.indexes i ON o.object_id = i.object_id
WHERE o.Type = 'U' -- User table
AND LEFT(i.Name, 1) <> '_'
-- Remove hypothetical indexes
ORDER BY o.NAME ,
i.name;
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment