Last active
December 9, 2024 06:10
-
-
Save r1d3rzz/003de74c76740595ca27bc40381dbdb3 to your computer and use it in GitHub Desktop.
check sql index Clustered
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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