getting depedency list from sysdepends

Hi,

 i am trying to find the list of dependent object for stored prcedure. I am not able to locate depenedency for sp that has temp table in sql statement.

i am trying to explain the scenerio by following examples

e.g--use northwind

Create proc testabc
as
BEGIN
create table #emp(fname varchar(50))
insert into #emp select firstname from employees

select * from #emp

drop table #emp


END

in above procedure employees table is used, but sp_depends didnot return any dependency.

 

 

2 example  use northwind

Create proc testabc2
as
BEGIN
select firstname into #emp  from employees
select employees.firstname,emptype.type into #tmp1
from #emp join employees on #emp.firstname=employees.firstname
join emptype on employees.employeeid=emptype.empid
select * from #tmp1
drop table #emp
drop table #tmp1
END

in above proc sysdepends has only one entry for employees table, but no enrty for emptype table.

Is there any way so that i could get the list all table and columns used in procedure like above

 

thnx in advance

lalit

 



Answer this question

getting depedency list from sysdepends

  • ChrisBradley

    lalit,

    Try the following. Use the name of the object after the like clause. This may take awhile to run depending on the size of syscomments

    select object_Name(id)

    from syscomments

    where text like '%[#]temp%'

    Hope this helps!

     

    Ron


  • shads

    This is equally as unreliable as sysdepends, if not more so. While you will catch cases where the object is referenced in dynamic SQL, or where the procedure was created before the object existed, but you will get other problems: (a) syscomments.text <= 8000 characters; objects with definitions longer than 8000 characters are broken out into multiple rows. What if your object name straddles the boundary between two rows (miss some procedures) (b) what if your object name is part of another name, or has more than one context (return false positives) (c) what if your object name is only mentioned in comments (return false positives) Not defending one or the other, or taking sides, just pointing out that the most reliable method is going to be documentation and source code control. Relying on SQL Server alone to define the dependency of the objects *you* create is something you should strive to avoid. A wrote in message news:2120a6ec-7edb-4cdc-9d6b-af09b7f9499d@discussions.microsoft.com... > lalit, > > Try the following. Use the name of the object after the like clause. > This may take awhile to run depending on the size of syscomments > > select object_Name(id) > > from syscomments > > where text like '%[#]temp%' > > Hope this helps! > > > > Ron > >
  • eyal k

    This is due to deferred name resolution. If a statement with temporary table is encountered then it is not parsed completely at the time of creation (syntax check is done for example). This will result in the permanent tables referenced in the SELECT statement that references a temporary table from not being recorded in sysdepends. The SELECT...INTO case is different in that it create a temporary table and that particular statement is parsed so you get reference of the employees table but subsequent statements that references the temporary table will be deferred. The dependency information in system tables can be broken very easily and in general you should not rely on it completely. Instead use a source code control system to maintain dependency in your scripts.

  • getting depedency list from sysdepends