Stored Procedures and Triggers

Learn about the database components like stored procedures and triggers.

We'll cover the following

Stored procedures

Stored procedures are precompiled SQL syntax that can be used repeatedly by executing its name in SQL Server. If there’s a query we frequently run, we write it from scratch, save the file somewhere, and then open it to run it; then, consider creating a stored procedure out of that query.

We can do the same with a stored procedure like SQL syntax that we’ll write from scratch and pass in a value for our WHERE clause. We can pass in specific values to achieve the result that we’re looking for so that we don’t always have to pass a parameter into a stored procedure.

For example, let’s say that as part of the HR department, we must run a query once a month to verify which employees are salaried and non-salaried, in compliance with labor laws and company policy.

Instead of opening a file frequently or writing the code from scratch, we can call the stored procedure we saved in the database to retrieve the information. We would specify the proper value (where 1 is TRUE and 0 is FALSE in this case).

Get hands-on with 1200+ tech skills courses.