Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Find the list of Stored Procedures which affect a particular column?

Im working on this large DB which has a lot of the business knowledge embedded in the SPs[I know!] and there is a lot of chaining between the SPs. i.e one stored proc calling another.

Im want to find out a list of stored procedures which update a particular column. How would I do that.

Using showplan_All as outlined in SQL Table and column Parser for stored procedures doesnt work for me, because this is a shared dev db.

using a Sp from master db scanning system text as described is not feasible because I dont have access to the master db.

So how can I find this informaion?

like image 478
Pradeep Avatar asked Mar 26 '09 15:03

Pradeep


People also ask

How do I find a list of Stored Procedures in a database?

View the list of stored procedure in a database using a query. To view the list of the stored procedure, you can query the information_schema. routines table. It contains the list of the stored procedure and stored functions created on the database.


2 Answers

Have you tried this : EXEC sp_depends @objname = [table name of the column you are interested in].

So for example, if you had a column named Price in a table named Product, you would execute this: EXEC sp_depends @objname = N'Product'.

Simply executing this would give you list of all sps, views, etc which depend on that particular table.

I use this all the time as I work with a db which has over 400 tables :-)

sp_depends page on MSDN

like image 72
Raj Avatar answered Oct 19 '22 06:10

Raj


From system view sys.sql_dependencies you can get dependencies at column level.

DECLARE @Schema SYSNAME
DECLARE @Table SYSNAME
DECLARE @Column SYSNAME

SET @Schema = 'dbo'
SET @Table = 'TableName'
SET @Column = 'ColumnName'

SELECT o.name
FROM sys.sql_dependencies AS d
  INNER JOIN sys.all_objects AS o ON o.object_id = d.object_id
  INNER JOIN sys.all_objects AS ro ON ro.object_id = d.referenced_major_id
  INNER JOIN sys.all_columns AS c ON c.object_id = ro.object_id AND c.column_id = d.referenced_minor_id
WHERE (SCHEMA_NAME(ro.schema_id)=@Schema) 
  and o.type_desc = 'SQL_STORED_PROCEDURE'
  and ro.name = @Table
  and c.name = @Column
GROUP BY o.name
like image 38
StanislawSwierc Avatar answered Oct 19 '22 05:10

StanislawSwierc