|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
stored procedure table dependencyAt which moment SQL creates a dependency with tables ? is it whenevr you
reference the table in the SP (insert or update or delete statm.......) or it is something else I have a table where I see some SP when I do Show dependencies but not others. thanks for your help The sysdepends catalog view only ever returns true dependencies if all
objects were created in the correct order and if none of them have been dropped and created after that. ML --- http://milambda.blogspot.com/ Hello,
I understand that you'd like to know when SQL creates a dependency of a SP. As I know, a dependency is created when the procedure is created unless Deferred Name Resolution is used. Also, a depndency is created only when the object such as table exists before the SP is created. Deferred Name Resolution and Compilation http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm _8_des_07_5wa6.asp The dependencies stored by SQL Server are not always reliable. The better option might be querying the syscomments table if you want to check if a table is referenced by any SP: SELECT DISTINCT o.name FROM dbo.syscomments c JOIN dbo.sysobjects o ON c.id = o.id WHERE o.xtype = 'P' AND c.text LIKE '%tbl_example%'; If you want to find other tables related to this one, for example, if you are looking more for if table A has column B, that is a foreign key to table C, so table C would have a dependency on table A, you may need to run sp_fkeys SP. If anything is unclear, or you have further questions, please feel free to let me know. We look forward to your reply. Best Regards, Peter Yang MCSE2000/2003, MCSA, MCDBA Microsoft Online Community Support ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications <http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx>. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at <http://msdn.microsoft.com/subscriptions/support/default.aspx>. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Somany thanks for the explanation. Just wanted to let you know that following
"ML" response, I checked this morning, the able creation date is 2000 and the SP in 2004. I will check again tomorrow and let you know. thanks again ""privatenews"" wrote: Show quote > Hello, > > I understand that you'd like to know when SQL creates a dependency of a SP. > > As I know, a dependency is created when the procedure is created unless > Deferred Name Resolution is used. Also, a depndency is created only when > the object such as table exists before the SP is created. > > Deferred Name Resolution and Compilation > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm > _8_des_07_5wa6.asp > > The dependencies stored by SQL Server are not always reliable. The better > option might be querying the syscomments table if you want to check if a > table is referenced by any SP: > > SELECT DISTINCT o.name > FROM dbo.syscomments c > JOIN dbo.sysobjects o > ON c.id = o.id > WHERE o.xtype = 'P' > AND c.text LIKE '%tbl_example%'; > > If you want to find other tables related to this one, for example, if you > are looking more for if table A has column B, that is a foreign key to > table C, so table C would have a dependency on table A, you may need to run > sp_fkeys SP. > > If anything is unclear, or you have further questions, please feel free to > let me know. We look forward to your reply. > > Best Regards, > > Peter Yang > MCSE2000/2003, MCSA, MCDBA > Microsoft Online Community Support > ================================================== > Get notification to my posts through email? Please refer to > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif > ications > <http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx>. > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues > where an initial response from the community or a Microsoft Support > Engineer within 1 business day is acceptable. Please note that each follow > up response may take approximately 2 business days as the support > professional working with you may need further investigation to reach the > most efficient resolution. The offering is not appropriate for situations > that require urgent, real-time or phone-based interactions or complex > project analysis and dump analysis issues. Issues of this nature are best > handled working with a dedicated Microsoft Support Engineer by contacting > Microsoft Customer Support Services (CSS) at > <http://msdn.microsoft.com/subscriptions/support/default.aspx>. > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. > > Hello,
My pleasure. If you need any further help, please feel free to post back. :-) Best Regards,Peter Yang MCSE2000/2003, MCSA, MCDBA Microsoft Online Partner Support ===================================================== This posting is provided "AS IS" with no warranties, and confers no rights. ====================================================== Hi, i played around with your script,
I have a SP called "sp_batch_UpdateByDistrib" that references 3 tables table1, table2,table3 in a select statement, when I issue your sql script I get so many lines(records) however, when I try to limit to only one table using o.name or o.id the query returns nothing, I modified the script as follows ****************************** SELECT DISTINCT o.name FROM dbo.syscomments c JOIN dbo.sysobjects o ON c.id = o.id WHERE o.xtype = 'P' AND c.text LIKE '%table1%' and o.name = 'table1'; *************************************** Any idea, thanks ""privatenews"" wrote: Show quote > Hello, > > My pleasure. If you need any further help, please feel free to post back. > :-) > > Best Regards, > > Peter Yang > MCSE2000/2003, MCSA, MCDBA > Microsoft Online Partner Support > > > ===================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. > ====================================================== > > > Hello,
Thank you for your reply. The sysobjects table in the query is used to search for the objects such as SPs referenced by table1. Therefore, it is not appropriate to add o.name=table1 in the query. The following query works on my side. SELECT DISTINCT o.name FROM dbo.syscomments c JOIN dbo.sysobjects o ON c.id = o.id WHERE o.xtype = 'P' AND c.text LIKE '%table1%' The result are all Stored procedures that reference the table1 in their script. If you still have concerns or questions, please do not hesitate to let's know. Thank you. Best Regards, Peter Yang MCSE2000/2003, MCSA, MCDBA Microsoft Online Partner Support ===================================================== This posting is provided "AS IS" with no warranties, and confers no rights. ====================================================== Yes, it is working on my side as well. The problem is I have several tables
containing the text "Table1" in the name as follows : table1 table1_article table1_article_obsolete ....... Sothat is why I need to give it table1 just to retrieve what concerns Table1 and not the other ones. Any idea That is why I need ""privatenews"" wrote: Show quote > Hello, > > Thank you for your reply. The sysobjects table in the query is used to > search for the objects such as SPs referenced by table1. Therefore, it is > not appropriate to add o.name=table1 in the query. The following query > works on my side. > > > SELECT DISTINCT o.name > FROM dbo.syscomments c > JOIN dbo.sysobjects o > ON c.id = o.id > WHERE o.xtype = 'P' > AND c.text LIKE '%table1%' > > The result are all Stored procedures that reference the table1 in their > script. > > If you still have concerns or questions, please do not hesitate to let's > know. Thank you. > > Best Regards, > > Peter Yang > MCSE2000/2003, MCSA, MCDBA > Microsoft Online Partner Support > > > ===================================================== > > This posting is provided "AS IS" with no warranties, and confers no rights. > ====================================================== > > > Hello,
I understand your concerns now. You may use the following statement to work around the issue. SELECT DISTINCT o.name FROM dbo.syscomments c JOIN dbo.sysobjects o ON c.id = o.id WHERE o.xtype = 'P' AND c.text LIKE '%table1%' AND c.text NOT LIKE '%table1_article%' AND c.text NOT LIKE '%table1_article_obsolete%' If this cannot meet your requirement, please let's know. I look forward to your reply. Best Regards, Peter Yang MCSE2000/2003, MCSA, MCDBA Microsoft Online Partner Support ===================================================== This posting is provided "AS IS" with no warranties, and confers no rights. ====================================================== |
|||||||||||||||||||||||