Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Locate specific columns used in procs

By Damien Alvarado,

Ever inherit a DB and wonder how many procs/views/triggers are referencing a column you have to make a DDL change to? You can change from VARCHAR(10) to VARCHAR(100), and everything looks cool until people start complaining about data being truncated. Where is that sp parameter definition that is truncating the data? This should help reduce your search efforts.

sp_depends shows you affected objects by table but not by column so I wrote this to show me where a particular column is getting used.

Also since sp_depends may not return all related procs I put a flag in to basically search all procedures.

Here is a sample call against the AdventureWorks DB.

USE [AdventureWorks]

DECLARE @return_value int

EXEC @return_value = [dbo].[LocateAffectedProcedures]
@in_TableName = N'HumanResources.Employee',
@in_Use_spDepends = FALSE,
@in_ColumnName1 = N'LoginId'

SELECT 'Return Value' = @return_value


When you see the output you will see that the column is used in only one Stored Procedure and which lines it is used on. sp_depends returns 18 entries and searching through them all would be a bummer.



Total article views: 991 | Views in the last 30 days: 4
Related Articles

No data returned - full text search.

Full text search - No Data Return


Data Profiling Column Functional Dependency T-SQL

This article demonstrates Data Profiling Functional Dependency


When sp_depends fails

sp_depends may not always return accurate information


Finding Column Dependencies

Most experienced DBAs know that sysdepends is not very reliable, so how can you find the dependencie...


String Search

Search for a string value within columns of data types CHAR, NCHAR, NTEXT, NVARCHAR, TEXT, VARCHAR, ...


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones