Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 4: DB2 Data Types and SQL Basics


What is SQL?

SQL (Structured Query Language) is the language used to talk to DB2. You write what you want, and DB2 figures out how to get it.

SQL in one sentence

  • SQL is a simple English-like language for storing, changing, and reading data in a relational database.
  • You describe what you want, not how to get it. DB2's optimizer picks the fastest access path.
  • The same SQL works in batch COBOL programs, in online CICS programs, and in interactive tools like SPUFI.

The SQL family

  • SQL is divided into sub-languages based on what the statement does:-
    1. DDL (Data Definition Language) :- Creates and changes database objects. Statements: CREATE, ALTER, DROP.
    2. DML (Data Manipulation Language) :- Reads and changes the data inside tables. Statements: SELECT, INSERT, UPDATE, DELETE.
    3. DCL (Data Control Language) :- Controls who can do what. Statements: GRANT, REVOKE.
  • Each sub-language is explained with examples in the following pages of this module.

How SQL works with DB2

  • In a COBOL program, SQL is written between EXEC SQL and END-EXEC.
  • The DB2 precompiler converts the SQL into COBOL calls before the COBOL compiler sees the program.
  • After every SQL statement, DB2 sets SQLCODE. Zero means success, +100 means no row found, negative means an error.
  • A COMMIT makes changes permanent. A ROLLBACK throws them away.





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant