I have a value in a table that was changed unexpectedly. The column in question is CreatedDate
: this is set when my item is created, but it's being changed by a stored procedure.
Could I write some type of SELECT
statement to get all the procedure names that reference this column from my table?
You can use ApexSQL Search, it's a free SSMS and Visual Studio add-in and it can list all objects that reference a specific table column. It can also find data stored in tables and views. You can easily filter the results to show a specific database object type that references the column
Disclaimer: I work for ApexSQL as a Support Engineer
One option is to create a script file.
Right click on the database -> Tasks -> Generate Scripts
Then you can select all the stored procedures and generate the script with all the sps. So you can find the reference from there.
Or
Source SQL SERVER – Find Column Used in Stored Procedure – Search Stored Procedure for Column Name
You can use the system views contained in
information_schema
to search in tables, views and (unencrypted) stored procedures with one script. I developed such a script some time ago because I needed to search for field names everywhere in the database.The script below first lists the tables/views containing the column name you're searching for, and then the stored procedures source code where the column is found. It displays the result in one table distinguishing "BASE TABLE", "VIEW" and "PROCEDURE", and (optionally) the source code in a second table:
If you run the query, use the "result as text" option - then you can use "find" to locate the search text in the result set (useful for long source code).
Note that you can set
@DisplaySPSource
to0
if you just want to display the SP names, and if you're just looking for tables/views, but not for SPs, you can set@SearchSP
to0
.Example result (find
CustomerID
in the Northwind database, results displayed via LinqPad):Note that I've verfied this script with a test view
dbo.TestOrders
and it found theCustomerID
in this view even thoughc.*
was used in theSELECT
statement (referenced tableCustomers
contains theCustomerID
and hence the view is showing this column).i had the same problem and i found that Microsoft has a systable that shows dependencies.
And this works with both
Views
andTriggers
.If you want to get stored procedures using specific column only, you can use try this query:
If you want to get stored procedures using specific column of table, you can use below query :