The benefits of using stored procedures in SQL Server rather than application code stored locally on client computers include:
-
They allow modular programming.
-
They allow faster execution.
-
They can reduce network traffic.
-
They can be used as a security mechanism.
Determine when to use stored procedures vs. SQL in the code
Stored procedures in SQL Server are similar to procedures in other programming languages in that they can:
-
Accept input parameters and return multiple values in the form of output parameters to the calling procedure or batch.
-
Contain programming statements that perform operations in the database, including calling other procedures.
-
Return a status value to a calling procedure or batch to indicate success or failure (and the reason for failure).
You can create a stored procedure once, store it in the database, and call it any number of times in your program. Someone who specializes in database programming may create stored procedures; this allows the application developer to concentrate on the code instead of SQL.