A precompiled set of Structured Query Language (SQL) statements that can be executed on demand by Microsoft SQL Server. Stored procedures are stored in a database.
They support features such as user-declared variables and conditional execution and can be run with a single call. They can accept parameters, and they can return parameters and status values.
They can also call other stored procedures. You can create permanent stored procedures for global administrative tasks or temporary ones for a specific task.
You create a stored procedure by using a series of SQL statements. SQL Server parses and analyzes the stored procedure and stores it in various system tables. When you execute it for the first time, it is loaded into memory and compiled, storing the execution plan in the procedure cache. By preparsing and prenormalizing a stored procedure, you can achieve significant performance gains compared to using a simple SQL query.
You can use stored procedures with SQL Server to
A trigger is a special type of stored procedure that you can use to enforce referential integrity in a database. Other types of stored procedures supported by SQL Server include the following: