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?
indexmetadatasql server
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?
Best Answer
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:
If you need to get this definition programmatically, then you can use SMO:
P.S. This answer was originally posted on this same question on Stack Overflow prior to the question getting copied over here.