DB2 Statements in cobol program
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.
1. DDL - Data Definition Language statements 2. DML - Data Manipulation Language statements 3. TCL - Transaction Control Language Statements 4. 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:
1. CREATE 2. ALTER 3. DROP
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:
- SELECT - INSERT - UPDATE - DELETE
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 can have two statements
1. COMMIT 2. ROLLBACK
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
1. GRANT 2. REVOKE
Data Control language concept explained in detail here .
DB2 CURSOR TYPES DB2 DDL Statement