In this topic, we described about DB2 Statements in cobol program in detail.
SQL (Structured Query Language) is used to retrieve the data from the database (DB2). In order to retrieve the data from DB2 in the program, SQL queries needs to be coded in the program.
The SQL queries should needs to code in between EXEC SQL and END-EXEC.
If the SQL queries are not coded in between EXEC SQL and END-EXEC, COBOL compiler will treat them as COBOL statements and tries to recognize and will throw the compilation error.
Coding SQL queries are mandatory to retrieve the data from database. So let’s discuss about what all the statements types in SQL are and then how it will be used in COBOL program.
SQL has three types of statements mainly. Those are -
|DDL||Data Definition Language statements|
|DML||Data Manipulation Language statements|
|TCL||Transaction Control Language Statements|
|DCL||Data Control Language statements|
DDL - Data Definition Language statements -
Data Definition Language is used to define (CREATE), alters (ALTER) and deletes (DROP) the database objects. Normally these DDL statements will be handled by DBA.
The database objects include schemas, tables, views, sequences, catalogs, indexes, and aliases. The main DDL statements are -
Data Definition Language concept explained in detail here .
DML – Data Manipulation Language -
Data Manipulation language used to manipulate the data inside the table. DML also uses to control the data inside the database table.
The main data manipulation statements are -
Data Manipulation language concept explained in detail here .
TCL: Transaction Control Language -
Transaction control language is used to control the transactions performed on the database. TCL can save or revoke the transactions applied on the database from SYNC point.
SYNC point is nothing but where thee COMMIT or ROLLBACK executed. TCL have two types of statements and those are -
Transaction Control Language concept explained in detail here .
DCL: Data Control language -
Data Control language is used for controlling of data by giving/revoking the access to retrieve the data based on the levels at users group level or individual user level.
One of the main advantages of DCL is, User groups can be restricted by revoking the access for the sensitive data. DCL has mainly two statements and those are -
Data Control language concept explained in detail here .