Search This Blog

Friday, August 5, 2011

Querying SysObjects in Sql Server

Sometimes as a developer we are required to change Table Structure or delete a table it self. In such a scenario it is always better to understand the impact of table change, to get the dependent Stored Procedures/Views of a table use sp_depends stroed procedure which will list out all Stored Procedures.Views that depends on table.

exec sp_depends 'tableName'

Using SP_Depends we can get dependencies information for Stored Procedure also.
exec sp_depends 'SpName'

When queried with sp_depends for a Stored Procedure it lists all the tables and columns referenced in Stored Procedure.

Another Important Sys Object that we can use is information_schema.routines

In scenarios like changing Column Name in a Table, before we need to update column names it is required for us to list out all the Stored Procedures which uses the particular column, so that we can update corresponding StoredProcedures with name change.

select Specific_name from information_schema.routines
where routine_definition like 'ColumnNametoChange'

No comments:

Post a Comment