From the course: Microsoft SQL Server 2022 Essential Training

Unlock this course with a free trial

Join today to access over 24,100 courses taught by industry experts.

Parameterized stored procedures

Parameterized stored procedures

- Stored procedures are a great way to simplify and consolidate the process of passing instructions to the database, but it's important to ensure that you're being efficient with their use. What you don't want is to create a thousand stored procedures that each address a single use case. Maintenance, and your sanity will be greatly improved by finding opportunities to create stored procedures that serve a variety of functions. One of the main ways of doing this is by utilizing parameters that alter the procedure's scope. These parameters can be specified by the end user when they run the procedure so that a single stored procedure can serve up results to a variety of situations or questions. Let's take a look at how this works by creating a new procedure in the Wide World Importers database, we'll put it inside of the warehouse schema, and I'll call it uspSelectProductsByColor. Then we'll add a parameter that will alter the…

Contents