0

This is the SQL that I am using:

select distinct [Table Name] = o.Name, [Found In] = sp.Name, sp.type_desc from sys.objects o inner join sys.sql_expression_dependencies sd on o.object_id = sd.referenced_id inner join sys.objects sp on sd.referencing_id = sp.object_id and sp.type in ('P', 'FN') where o.name = 'PacManPackage' and o.name = 'PacManCompanyPackage' order by sp.Name 

If I remove the o.name and view with only one table it works. But I need to find stored procedures that reference a few different tables (but they must reference all of them)

2
  • 1
    Which dbms? (Doesn't look like ANSI SQL at all.) Commented Feb 3, 2015 at 16:02
  • How can "o.name 'PacManPackage' and o.name = 'PacManCompanyPackage'" both be true? Commented Feb 3, 2015 at 16:03

1 Answer 1

2

If I've understood you correctly, you want to find stored procedures or scalar functions that reference all of a set of tables? How about this for a quick and dirty answer;

select sp.name from sys.objects sp inner join sys.sql_expression_dependencies sed on sed.referencing_id = sp.object_id inner join sys.objects t on t.object_id = sed.referenced_id and t.type = 'U' where sp.type in ('P', 'FN') and t.name in ('PacManPackage', 'PacManCompanyPackage') group by sp.name having count(*) = 2 -- change accordingly 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.