Ian Beckett

RSS feed

    Recent comments

    Authors

    find out which tables are referenced by a stored procedure

    Use this script to get a list of tables that are referenced in a stored procedure.  Just replace the value set for the variable "@sproc" to the name of the sproc you are evaluating:

    declare @sproc varchar(8000)

    set @sproc='spMyStoredProc'

    CREATE TABLE #endchars (endchar char(1))

    INSERT INTO #endchars (endchar)

    select ' ' union select ')' union select ']' union select ';'
    union select char(9) union select char(10) union select char(13)

    select so.name
    from sysobjects so, syscomments sc, #endchars ec
    where so.type='U'
        and object_name(sc.id)=@sproc
    group by so.name
    having sum(charindex(so.name+ec.endchar ,sc.text+' '))<>0
    order by name

    DROP TABLE #endchars

    source: http://www.sqlservercentral.com/scripts/SQL+Server+2000/65162/


    Categories: SQL 2000 | SQL 2005 | SQL 2008
    Posted by ibeckett on Tuesday, December 30, 2008 12:40 PM
    Permalink | Comments (0) | Post RSSRSS comment feed