Wednesday, April 30, 2014

Generate table to stored Procedure cross references

 

By Marcus Dallasandro, 2014/04/25

Lists Tables and Store Procedure references. Runs a bit slow but appears to be accurate. Just paste this script into SSMS for the desired database.

 

WITH TableList_CTE (TableName)
AS
(
SELECT TABLE_NAME + CHAR(32) as TableName
   FROM INFORMATION_SCHEMA.TABLES T
  WHERE t.TABLE_TYPE='BASE TABLE'
)
SELECT TableName,OBJECT_NAME(object_id) as StoredProcedure
    FROM  sys.sql_modules S
    Join TableList_CTE on 1=1
    WHERE objectproperty(object_id,'IsProcedure') = 1
    AND CHARINDEX(TableName,Definition,0)<>0
  Order by TableName

No comments:

Post a Comment