Skip to content

Instantly share code, notes, and snippets.

@r1d3rzz
Last active December 9, 2024 06:10
Show Gist options
  • Save r1d3rzz/003de74c76740595ca27bc40381dbdb3 to your computer and use it in GitHub Desktop.
Save r1d3rzz/003de74c76740595ca27bc40381dbdb3 to your computer and use it in GitHub Desktop.
check sql index Clustered
ALTER DATABASE test SET TRUSTWORTHY ON;
GO
SELECT
'CREATE INDEX ' + ix.name + ' ON ' + t.name + '(' + CAST(STRING_AGG(c.name, ', ') AS VARCHAR(MAX)) + ');' AS create_index_statement
FROM
sys.indexes ix
JOIN
sys.tables t ON ix.object_id = t.object_id
JOIN
sys.index_columns ic ON ic.index_id = ix.index_id AND ic.object_id = t.object_id
JOIN
sys.columns c ON c.column_id = ic.column_id AND c.object_id = t.object_id
GROUP BY
ix.name, t.name,C.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment