|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 12:43 AM
Points: 582,
Visits: 1,601
|
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 12:43 AM
Points: 582,
Visits: 1,601
|
|
I've since found another couple of issues. One is that it in the same way as I need and #endchars table to stop table1 matching on table12, I would also need a #startchars table to stop table1 matching on constable1. However if I include a startchars as another cross join like I do endchars, performance goes down the drain.
For this reason, I worked on a modified version using patindex and a blacklist of endchars (rather than the whitelist above).
Note that tables from other databases won't be considered (as we're looking at sysobjects from the current db.) Also any tables which are commented out will nonetheless be included.
declare @sproc varchar(256)
set @sproc = 'spToBeSearched'
select so.name from sysobjects so, syscomments sc where so.type = 'U' and object_name(sc.id) = @sproc group by so.name having sum(patindex('%[^a-zA-Z0-9~]' + replace(so.name,'_','~') + '[^a-zA-Z0-9~]%', replace(sc.text,'_','~') + ' ')) <> 0 order by name
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: 2 days ago @ 2:04 AM
Points: 1,968,
Visits: 1,819
|
|
If you do not use dynamic sql in your sp, you have the sysdepends table with all dependencies between objects.
Here you are: SELECT object_name(id) as sp,object_name(depid) as dep_obj FROM sysdepends WHERE object_name(id) = 'mysp_elab'
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 12:43 AM
Points: 582,
Visits: 1,601
|
|
Hi Carlo,
sysdepends is notoriously unreliable due to deferred name resolution - which means that I can create a stored procedure before the objects it references exist.
In the stored procedures I tested with, sysdepends only returned about half of the referenced tables (20 instead of 40).
Regards,
David.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, January 26, 2011 1:32 PM
Points: 146,
Visits: 327
|
|
David,
Weird stuff with your code - it prints out a table NOT in the SP.
Also, it DOES print tables from another DB - could this be because they are in the SP as DB2..DBTable1 ?
Wondering, Doug
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, January 26, 2011 1:32 PM
Points: 146,
Visits: 327
|
|
Carlo,
Your code did not list ANY tables in the SP, but it did list another SP called from within it?
Are either yours or David's routines dependent upon ownership in the code eg spname vs tablename vs dbo.spname vs dbo.tablename or database.dbo.tablename?
Best, Doug
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 12:43 AM
Points: 582,
Visits: 1,601
|
|
Hi Doug,
Thanks for your feedback! The table names it displays come from sysobjects which is dependent on the database you're running under i.e. the USE statement. I can't imagine that sysobjects in one database could contain tables found in another db. Is it possible you're running the database against a different database? (master perhaps?).
By the way, which script are you referring to - I'd recommend the script in the forum, rather than in the article. Do you get the same results (or similar anomolies) with both?
Again thanks for taking the time to share your findings.
Happy new year,
David.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: 2 days ago @ 2:04 AM
Points: 1,968,
Visits: 1,819
|
|
Please, try this one: exec sp_MSdependencies N'[dbo].[mysp_elab]', null, 1053183
Third parameter is 1053183, that means only table named in the sp. Without parms, it returns all dipendencies: table used in the sp and their FK.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 12:43 AM
Points: 582,
Visits: 1,601
|
|
Hi Carlo,
I've just tried out your latest post, compared against my script.
Against a (random) sample stored procedure, yours retrieves 9 tables (listed below)
ATTR_LN_PTF_BENCH BENCHMARK D_TIME PORTF_SHARE PORTFOLIO PORTFOLIO_PERFORMANCES S_PORTF_SHARE_PERF SHARE_PERF_SETTING T_SHARE_CLASS
whereas mine retrieves 13 tables (also listed)
ATTR_LN_PTF_BENCH BENCHMARK D_TIME PERF_CALENDAR PORTF_SHARE PORTFOLIO PORTFOLIO_PERFORMANCES S_PORTF_SHARE_CARAC S_PORTF_SHARE_PERF S_PORTFOLIO_CARAC SHARE_NET_VALUE SHARE_PERF_SETTING T_SHARE_CLASS
I've checked the tables which aren't in your results and they are 1) not commented 2) not dynamic SQL. I just want to reiterate that sysdepends is totally unreliable, and sp_MSdependencies is built on sysdepends. (Do an sp_helptext on it and search for sysdepends.)
ANY SOLUTION based on sysdepends isn't going to work.
Regards,
David.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: 2 days ago @ 2:04 AM
Points: 1,968,
Visits: 1,819
|
|
| sysdepends lists tables only if they are in the same database and the sp is created after the table. To update syspedends please ALTER PROCEDURE and then run exec sp_MSdependencies N'[dbo].[mysp_elab]', null, 1053183
|
|
|
|