what is stored procedure

what is stored procedure

1 year ago 40
Nature

A stored procedure is a subroutine available to applications that access a relational database management system (RDBMS) . It is a group of SQL statements that are stored together in a database and can be reused over and over again. Stored procedures are stored in the database data dictionary and can be used for data-validation or access-control mechanisms. They can also consolidate and centralize logic that was originally implemented in applications, saving time and memory.

Stored procedures can perform one or multiple DML operations on the database, and return a value, if any. They can receive variables, return results or modify variables and return them, depending on how and where the variable is declared. Stored procedures can accept input parameters and return multiple values of output parameters. They can be used to accomplish the same task as user-defined functions (UDFs), but functions are designed to send their output to a query or T-SQL statement, while stored procedures are designed to return outputs to the application.

Benefits of using stored procedures include reusability, easy modification, security, low network traffic, and increased performance. Stored procedures can reduce network traffic between clients and servers because the commands are executed as a single batch of code, meaning only the call to execute the procedure is sent over a network, instead of every single line of code being sent individually. Upon the first use, a plan for the stored procedure is created and stored in the buffer pool for quick execution for the next time, which increases performance.

To create a stored procedure, the syntax is CREATE PROCEDURE procedure_name AS sql_statement . Stored procedures can be executed using the EXEC statement. Parameters can be passed to stored procedures so that the stored procedure can act on the passed parameter values. The most important part of a stored procedure is the parameters, which are used to pass values to the procedure.

In summary, a stored procedure is a group of SQL statements that are stored together in a database and can be reused over and over again. They can perform one or multiple DML operations on the database, and return a value, if any. Stored procedures provide benefits such as reusability, easy modification, security, low network traffic, and increased performance. They can be created using the CREATE PROCEDURE statement and executed using the EXEC statement.

Read Entire Article