- Find out how many stored procedure are using Cross Database Queries, so we want to search for Database name in all the stored procedures in a database.
- Find out in how many stored procedure a table/view is used in a Database? This can be situation where we are planning to change the name of table/view and want to make sure if any Stored Procedure/s will be effected.
- Find out a column name used in Stored Procedure/s in SQL Server Database.
- Find out some comments in all the Stored Procedure to see who created those Stored Procedure, if Creator name is used in the comments.
System.sql_modules and sys.syscomments system views can be used to dig into the definition of objects and search if any other object is used in the definition or not. Let's suppose if I am looking for comments in objects Creator Name=Aamir. I can use both system views to find out required information by using below queries.
SELECT OBJECT_NAME(OBJECT_ID) AS ObjectName,
definition AS ObjectDefinition
WHERE definition LIKE '%Creator Name=Aamir%'
SELECT OBJECT_NAME(id) AS ObjectName,
TEXT AS ObjectDefinition
WHERE TEXT LIKE '%Creator Name=Aamir%'