How check that how many stored procedure will affect after deleting one table in SQL [duplicate]

感情迁移 提交于 2019-12-08 00:57:21

问题


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.


回答1:


Using sp_depends:

EXEC sp_depends @objname = N'yourtablename'



回答2:


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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/27654344/how-check-that-how-many-stored-procedure-will-affect-after-deleting-one-table-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!