How can I find out what tables a T-SQL stored procedure creates when it runs?
We have hundreds of stored procedures and I am looking for hints on how to go about this.
We can do most things on the SQL Server 2012 itself, or in C# (Framework 3.5).
How can I find out what tables a T-SQL stored procedure creates when it runs?
We have hundreds of stored procedures and I am looking for hints on how to go about this.
We can do most things on the SQL Server 2012 itself, or in C# (Framework 3.5).
This StackOverflow post should help you, entitled 'How do I find a stored procedure containing text'.
It runs various commands to extract the stored procs and their associated text, when it just doing a LIKE on the content.
For reference, this is:
DECLARE @TextToSearchFor varchar(50) = 'CREATE TABLE'
SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%' + @TextToSearchFor + '%'
AND ROUTINE_TYPE='PROCEDURE'
SELECT OBJECT_NAME(id)
FROM SYSCOMMENTS
WHERE [text] LIKE '%' + @TextToSearchFor + '%'
AND OBJECTPROPERTY(id, 'IsProcedure') = 1
GROUP BY OBJECT_NAME(id)
SELECT OBJECT_NAME(object_id)
FROM sys.sql_modules
WHERE OBJECTPROPERTY(object_id, 'IsProcedure') = 1
AND definition LIKE '%' + @TextToSearchFor + '%'