How to access the text definition of sql indexes I am able to access the text definition of stored procedures, views, triggers and functions from sys.sql_modules. I want to get the text definition of indexes.

How can I get the text definition of indexes in SQL Server?
The objects that have definitions found in the sys.sql_modules Catalog View are the only ones that have full definitions, and indexes are not in this group. The sys.check_constraints and sys.default_constraints Catalog Views have partial definitions, but again, those aren't indexes. So no, you are not going to find the text definition of indexes.

What you can find, however, is the meta-data related to indexes that can be used to construct the full text definition. You would find that info in the following Catalog Views:


sys.indexes
sys.index_columns
sys.columns
sys.data_spaces
sys.key_constraints
sys.xml_indexes
sys.partition_schemes  (might be needed for partitioned indexes)


If you need to get this definition programmatically, then you can use SMO:


SQL Server Management Objects (SMO) Programming Guide
Automated Script-generation with Powershell and SMO


P.S. This answer was originally posted on this same question on Stack Overflow prior to the question getting copied over here.