Help with a Sql search.

I need to search all of the stored procedures in my database that contain a table named "Customers". I have this query which partially works:

SELECT OBJECT_NAME(object_id), OBJECT_DEFINITION(object_id) FROM sys.procedures
WHERE OBJECT_DEFINITION(object_id) like '%Customers%'. This works because I am using the wildcards % padding the string. However if I do a straight search for the table name with no wild cards, it does not work:
So how can I search precisely for the specific table name without using wild cards?

SELECT OBJECT_NAME(object_id), OBJECT_DEFINITION(object_id) FROM sys.procedures
WHERE OBJECT_DEFINITION(object_id) like 'Customers'.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nakul VachhrajaniTechnical Architect, Capgemini IndiaCommented:
The object definition would contain the actual DDL (e.g. In case of a stored procedure, it would be CREATE PROCEDURE). When wild cards are not used, the database engine does a perfect match which would fail because no object would have a definition that only consists of the table name.
brgdotnetcontractorAuthor Commented:
No, I think there is some confusion here. I want to find all stored procedures in a database which have a particular string in them. Like for example a table name. I don't care what kind of DML is done on the table name I am searching for. I don't even care if the table name is commented out in the stored procedure. I just want to find all stored procedures which contain a table name I am searching for. For example, suppose I have this stored procedure  named UniverseParser with some the following Sql below. If I search the database for all stored procedures that have the table name "MarsTable", then this stored procedure UniverseParser would come up.

Update MarsTable
SELECT PlanetName From Planets
Deepak ChauhanSQL Server DBACommented:
I guess you want to search based on the exact table name. You can use this script.

select as SPNAME, s.referenced_entity_name as TableName from sys.procedures p
join sys.sql_expression_dependencies s on p.object_id=s.referencing_id
where s.referenced_entity_name = <Your TableName>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.