I recently came across some code where various input parameters were declared in the creation of a stored procedure though weren't actually being used anywhere in the script. As it turned out, the developer had modified the code at some point, removing these parameters as they were no longer needed for filtering purposes, but forgot to remove them from the input parameter list.
The stored procedure below will scan all relevant objects and return any that have unused input parameters, outputting the following:
-
schema_name: Schema name of the object in which the unused input parameter was found
-
object_name: Object name in which the unused input parameter was found
-
parameter_name: Name of the unused input parameter
-
object_type: Type of object in which the unused input parameter was found (for example: stored procedure, scalar function, etc.)
-
data_type: Data type of the unused input parameter
-
is_output: Indicator specifying whether or not the unused input parameter was defined with the "OUTPUT" clause
-
definition: Definition details of the object in which the unused input parameter was found
To execute the stored procedure simply pass it the name of the database to search against:
EXECUTE dbo.usp_Unused_Input_Parameters
@v_Database = N'my_database'
NOTE: Always make sure that no other objects or applications are referencing any input parameters that you decide to remove. For example: if you remove an input parameter from procedure A, but procedure B calls procedure A and passes to it one of the now removed parameters then you will also need to update procedure B's call to procedure A.
Any friendly feedback is always welcome. Enjoy!