2

I am using SQL 2012.

I have large Database Structure in my project. I have around 10000 Stored Procedure in my Database.

I have to delete one table from the database, Is there any way that I can directly check that by deleteting my table how many stored procedure will affect.

Any help Will Be appriciated.

Hardik Parmar
  • 1,053
  • 3
  • 15
  • 39

4 Answers4

6

Using sp_depends:

EXEC sp_depends @objname = N'yourtablename'
dotnetom
  • 24,551
  • 9
  • 51
  • 54
knkarthick24
  • 3,106
  • 15
  • 21
1

If you are using SQL Server Management Studio, you can right click table and select "View Dependencies" to view the dependent objects

Amer Zafar
  • 419
  • 2
  • 11
  • 1
    A problem with this is that it will not show you where the table is referenced by dynamic sql – DeanOC Dec 26 '14 at 08:29
1

1) Procedures, Views, Functions, Triggers, FK's - view dependancies. View dependancies will give you all of the objects who referenced the table at the compile phase.

2) Procedures, Views, Functions, Triggers

select object_name(id),* 
from sys.syscomments 
where text like '%tableName%' 

Will give you names of objects where your table name appears. This is a string search. So if it appears in comments or dynamic sql, it will also be caught.

*** if you're using dynamic sql that receives the table name from an outside source, this is something you can only catch at the execution stage.

3) Jobs -

SELECT  *
FROM    msdb.dbo.sysjobs j
JOIN    msdb.dbo.sysjobsteps js
    ON  js.job_id = j.job_id 
WHERE   js.command LIKE N'%TableName%'

Will give you the names of the jobs where the table is found in the steps code. This is also a string matching search.

Amir Pelled
  • 591
  • 4
  • 13
0

Import the database into a new SSDT project.

Then you can right click the object name and use "find all references".

You may also/instead want to search for the text string in all files if it might be referenced by dynamic SQL.

Martin Smith
  • 438,706
  • 87
  • 741
  • 845