Technical Article

Script to list user tables with related procedures

,

This script interrogates the system tables and provides a list of user tables with related stored procedures and triggers. Alternately, reordering the temporary table provides a list of stored procedures with the table names used in each procedure.

set nocount on

create table #TableProList (
ID int identity (1,1),
TblName varchar(35),
Procedures varchar(50))

DECLARE TBList CURSOR
FOR select name FROM SYSOBJECTS WHERE TYPE = 'U'
AND name <>'dtproperties'

DECLARE @name varchar(35)
OPEN TBList

FETCH NEXT FROM TBList INTO @name
WHILE (@@fetch_status <> -1)
BEGIN

INSERT #TableProList(TBLNAME, PROCEDURES)
SELECT DISTINCT @NAME, A.name from sysobjects A, syscomments B WHERE B.text like '%' + @NAME + '%' AND A.id = B.id

FETCH NEXT FROM TBList INTO @name
END

CLOSE TBList
DEALLOCATE TBList

select TblName, Procedures from #TableProList order by ID

drop table #TableProList

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating