SQL procedures and modules

 

The second technique for sending SQL statements to the DBMS is through modules. Briefly, a module consists of a group of procedures which are called from the host programming language. Each procedure contains a single SQL statement, and data is passed to and from the procedure through parameters.

 

A module can be thought of as an object library that is linked to the application code. However, exactly how the procedures and the rest of the application are linked is implementation-dependent. For example, the procedures could be compiled into object code and linked directly to the application code; they could be compiled and stored on the DBMS and calls to access plan identifiers placed in the application code; or they could be interpreted at run time.

 

The main advantage of using modules and procedures as opposed to embedding SQL statements in an application source code file is that this approach cleanly separates SQL statements from high-level programming languages. This separation makes application development easier because only the modules containing SQL statements have to be precompiled. Also, in theory, this approach should allow you to make changes to one part of an application without having to change the other. The two parts only need to be relinked to produce a modified application.