How can I search through a SQL Server database schema to find StoredProcs with a specified set of args?

≡放荡痞女 提交于 2019-12-25 07:39:48

问题


I am trying to deduce which Stored Proc is used to return a specific set of data.

The challenge is that the database has hundreds of Stored Procs. Is there a way I can query the schema to locate all StoredProcs that have parameters named, for instance:

Unit
Member
BegDate
EndDate

...or, barring that, find SPs that take four args?

That would narrow things down a bit and ameliorate matters.


回答1:


All of the information you want to find about stored procedures, you can find in tables like INFORMATION_SCHEMA.PARAMETERS, SYS.PARAMATERS, SYS.PROCEDURES, SYS.SQL_MODULES, etc.

Your issue can be solved by querying the PARAMETER_NAME in INFORMATION_SCHEMA.PARAMETERS.

e.g.

; WITH T AS (SELECT [specific_name] FROM information_schema.parameters WHERE [parameter_name] = '@Unit'
UNION ALL
SELECT [specific_name] FROM information_schema.parameters WHERE [parameter_name] = '@Member'
UNION ALL
SELECT [specific_name] FROM information_schema.parameters WHERE [parameter_name] = '@BegDate'
UNION ALL
SELECT [specific_name] FROM information_schema.parameters WHERE [parameter_name] = '@EndDate')
SELECT [specific_name] 
FROM T
GROUP BY [specific_name] HAVING COUNT(*) = 4

Or to just find all procedures with 4 parameters:

SELECT [specific_name] FROM information_schema.parameters GROUP BY [specific_name] HAVING COUNT(*) = 4


来源:https://stackoverflow.com/questions/34212973/how-can-i-search-through-a-sql-server-database-schema-to-find-storedprocs-with-a

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