Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Unused Input Parameters

By Sean Smith,

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

    @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!

Total article views: 2301 | Views in the last 30 days: 14
 
Related Articles
FORUM

How to make input parameters mandatory in Stored Procedure ?

How to make input parameters mandatory in Stored Procedure ?

FORUM

Execute Stored Procedure with Select Statement as Input Parameters

Execute Stored Procedure with Select Statement as Input Parameters

FORUM

Parameterised Input stored procedure

Parameterised Input stored procedure

FORUM

xml input for stored procedure

xml input for stored procedure

FORUM

Parameter passing

Input and output parameter

Tags
functions    
input    
parameters    
stored procedures    
unused    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones