I have a value in a table that was changed unexpectedly. The column in question is CreatedDate
, which 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?
9条答案
按热度按时间flseospp1#
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
kqqjbcuj2#
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 :
v7pvogib3#
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
qxgroojn4#
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).Note for LinqPad users: In C#, you can use
dc.ExecuteQueryDynamic(sqlQueryStr, new object[] {... parameters ...} ).Dump();
and have the parameters as@p0
...@pn
inside the query string. Then you can write a static extension class and save it under My Extensions to be used in your LinqPad queries. The data context can be passed from the query window asDataContextBase dc
via parameter, i.e.public static void SearchDialog(this DataContextBase dc, string searchString = "%")
inside a public static extension class (in LinqPad 6, it isDataContext
). Then you can rewrite the SQL query above as a string with parameters and invoke it from the C# context.dsekswqp5#
try this..
or you can generate a scripts of all procedures and search from there.
b4wnujal6#
i had the same problem and i found that Microsoft has a systable that shows dependencies .
And this works with both
Views
andTriggers
.kuhbmx9i7#
-- Search in All Objects
-- Search in Stored Procedure Only
xyhw6mcr8#
wfauudbj9#
You can use the below query to identify the values. But please keep in mind that this will not give you the results from encrypted stored procedure.