Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all stored procedures that reference a specific column in some table

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?

like image 818
Pomster Avatar asked Oct 23 '13 10:10

Pomster


People also ask

How do I identify all stored procedures referring a particular table in mysql?

You need to query Mysql. proc table, here's the documentation: The mysql. proc table contains information about stored procedures and stored functions.

How do I check if a column exists in a stored procedure in SQL Server?

IF EXISTS(SELECT 1 FROM sys. columns WHERE Name = N'Name' AND Object_ID = Object_ID(N'dbo. SampleTable')) SELECT 'Column exists in table' AS [Status] ; ELSE SELECT 'Column does not exist in table' AS [Status]; You can see in below result, column Name exists in table.


1 Answers

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

-- Search in All Objects SELECT OBJECT_NAME(OBJECT_ID), definition FROM sys.sql_modules WHERE definition LIKE '%' + 'CreatedDate' + '%' GO  -- Search in Stored Procedure Only SELECT DISTINCT OBJECT_NAME(OBJECT_ID), object_definition(OBJECT_ID) FROM sys.Procedures WHERE object_definition(OBJECT_ID) LIKE '%' + 'CreatedDate' + '%' GO 

Source SQL SERVER – Find Column Used in Stored Procedure – Search Stored Procedure for Column Name

like image 87
huMpty duMpty Avatar answered Sep 20 '22 18:09

huMpty duMpty