Quantcast
Viewing all articles
Browse latest Browse all 20

Finding Object References in SQL Server 2005 & 2008

You can use the following query to search through all of the code in a SQL Server database for a given string.  This is often useful when identifying dependencies in code.

 

–Make sure to set the database context here (i.e. “use master”)
GO
–Specify the search string (surrounded by wildcards “%”)
DECLARE @SearchString NVARCHAR(100); SET @SearchString = ‘%Column01%’
–Search through the database code for your results
SELECT DISTINCT
sys.schemas.name + ‘.’ + sys.objects.name AS ObjectName
FROM
sys.sql_modules
INNER JOIN
sys.objects
ON
sys.sql_modules.object_id = sys.objects.object_id
INNER JOIN
sys.schemas
ON
sys.objects.schema_id = sys.schemas.schema_id
WHERE
sys.sql_modules.definition LIKE @SearchString
ORDER BY
ObjectName
GO

 

 

 

—-

SQL Server Expert, Steve Abraham, holds 8 Microsoft certifications and specializes in SQL Server and .Net Framework architecture, high availability, capacity planning, development, and performance tuning, and SQL Server Recovery.


Posted in Programming SQL Server, SQL Server 2005, SQL Server 2008, T-SQL Tagged: Column Reference, Table Reference Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 20

Trending Articles