Monday, November 16, 2009

Find All Functions and Procedures That Have No Parameters

To find all functions that have no parameters, use this code:
SELECT o.name AS FunctionName
FROM sys.objects                    AS o
LEFT OUTER JOIN sys.all_parameters  AS p
ON o.[object_id] p.[object_id]
WHERE o.type IN ('AF''FN''IF''TF')
  AND 
p.parameter_id IS NULL
ORDER BY o.name

To find all stored procedures that have no parameters, use this code:
SELECT o.name AS ProcedureName
FROM sys.procedures                 AS o
LEFT OUTER JOIN sys.all_parameters  AS p
ON o.[object_id] p.[object_id]
WHERE 1
  
AND p.parameter_id IS NULL
ORDER BY o.name

No comments:

Post a Comment