| Stored Procedure |
Article Index for Stored |
Website Links For Stored |
Information AboutStored Procedure |
| CATEGORIES ABOUT STORED PROCEDURE | |
| database management systems | |
|
Typical uses for stored procedures include Data Validation (integrated into the database) or Access Control mechanisms. Furthermore, stored procedures are used to consolidate and centralize logic that was originally implemented in applications. Large or complex processing that might require the execution of several SQL statements is moved into stored procedures and all applications call the procedures only. Stored procedures are similar to User-defined Functions (UDFs). The major difference is that UDFs can be used like any other expression within SQL statements, whereas stored procedures must be invoked using the CALL statementCALL procedure(…) Stored procedures can return Result Set s, i.e. the results of a SELECT statement. Such result sets can be processed using Cursor s by other stored procedures by associating a result set locator, or by applications. Stored procedures may also contain declared variables for processing data and cursors that allow it to loop through multiple rows in a table. The standard Structured Query Language provides IF, WHILE, LOOP, REPEAT, and CASE statements, and more. Stored procedures can receive variables, return results or modify variables and return them, depending on how and where the variable is declared.IMPLEMENTATION The exact and correct implementation of stored procedure varies from one database system to another. Most major database vendors support them in some form. Depending on the database system, stored procedures can be implemented in a variety of Programming Language s, for example SQL , Java , or C and C++ . Stored procedures written in non-SQL programming languages may or may not execute SQL statements themselves. The increasing adoption of stored procedures led to the introduction of procedural elements to the SQL language in the standard. ADVANTAGES A variety of advantages can be obtained through the use of stored procedures. Pre-compilation of SQL statements SQL statements implemented as stored procedures in some cases run ''faster'', as they can be pre-compiled. Execution plans for compiled statements can be stored in the database, together with the procedure. This can remove the compilation overhead that is typically required in situations where software applications send inline SQL queries to a database. However, most database systems implement statement caches to avoid repetitive compilation of dynamic SQL statements. In addition, pre-compiled SQL statements, while avoiding some overhead, add to the complexity of creating an optimal execution plan because not all arguments of the SQL statement are supplied at compile time. Depending on the specific database implementation and configuration, mixed performance results will be seen from stored procedures versus generic queries or user defined functions . Execution on a database server Stored procedures can run directly within the database engine. In a production system, this typically means that the procedures run entirely on a specialized database server, which has direct access to the data being accessed. The benefit here is that network communication costs can be avoided completely. This becomes particularly important for complex series of SQL statements. However, note that unnecessary or excessive procedural statement execution in the database server (typically a singular shared resource) may impair overall enterprise system performance - i.e., while application servers can often be dramatically scaled horizontally for increased processing capacity, the same is not generally or as easily accomplished for database servers. Therefore, a growing school of thought (not among old school DBAs of course) advocates the database be used for what it's best at - i.e., a very efficient file cabinet. Thereby restricting any database-local procedural executions to only very specific cases rather than the old school ubiquity - instead advocating the use of advanced object oriented domain class ontologies and reusable parameterized SQL generation. However, the culture war on this point is likely to continue for years more. Simplification of data management Stored procedures allow for Business Logic to be embedded as an API in the database, which can simplify data management and reduce the need to encode the logic elsewhere in client programs. This may result in a lesser likelihood of data becoming corrupted through the use of faulty client programs. Thus, the database system can ensure data integrity and consistency with the help of stored procedures. Some critics claim that databases should be for storing data only, and that business logic should only be implemented by writing a ''business layer'' of code, through which client applications should access the data. However, the use of stored procedures does not preclude the use of a ''business layer''. Security Carefully written stored procedures may allow for fine grained security permissions to be applied to a database. For example, client programs might be restricted from accessing the database via any means except those that are provided by the available stored procedures. OTHER USES In some systems, stored procedures can be used to control transaction management; in others, stored procedures run inside a transaction such that transactions are effectively transparent to them. Stored procedures can also be invoked from a Database Trigger or a condition handler. For example, a stored procedure may be triggered by an insert on a specific table, or update of a specific field in a table, and the code inside the stored procedure would be executed. Writing stored procedures as condition handlers also allow DBAs to track errors in the system with greater detail by using stored procedures to catch the errors and record some audit information in the database or an external resource like a file. EXTERNAL LINKS
|
|
|