Before you can run your application program, a relationship between the program and any referred-to tables and views must be established. This process is called binding.
The result of binding is an access plan. The access plan is a control structure that describes the actions necessary to satisfy each SQL request. An access plan contains information about the program and about the data the program intends to use. For distributed relational database work, the access plan is stored in the SQL package and managed by the server along with the SQL package.
SQL automatically attempts to bind and create access plans when the result of a successful compile is a program or service program object. If the compile is not successful or the result of a compile is a module object, access plans are not created. If, at run time, the database manager detects that an access plan is not valid or that changes have occurred to the database that might improve performance (for example, the addition of indexes), a new access plan is automatically created. If the application server (AS) is not an iSeries™ server, then a bind must be done again using the Create Structured Query Language Package (CRTSQLPKG) command. binding does three things:
During the bind process, the SQL statements are checked for valid table, view, and column names. If a referred to table or view does not exist at the time of the precompile or compile, the validation is done at run time. If the table or view does not exist at run time, a negative SQLCODE is returned.
In selecting an access path, indexes, table sizes, and other factors are considered when SQL builds an access plan. The bind process considers all indexes available to access the data and decides which ones (if any) to use when selecting a path to the data.
If all the SQL statements are valid, the bind process builds and stores access plans in the program.
If the characteristics of a table or view your program accesses have changed, the access plan might no longer be valid. When you attempt to use an access plan that is not valid, the server automatically attempts to rebuild the access plan. If the access plan cannot be rebuilt, a negative SQLCODE is returned. In this case, you might have to change the program's SQL statements and reissue the CRTSQLxxx command to correct the situation.
For example, if a program contains an SQL statement that refers to COLUMNA in TABLEA and the user deletes and recreates TABLEA so that COLUMNA no longer exists, when you call the program, the automatic rebind is unsuccessful because COLUMNA no longer exists. You must change the program source and reissue the CRTSQLxxx command.