![](https://csdnimg.cn/release/download_crawler_static/12761636/bg7.jpg)
6
Chapter 2: Structured Query Language (SQL) Db2 Today
7
z Data Control Language (DCL) statements: Used to give (grant)
and take away (revoke) authorities and privileges. Authorities convey
the right to perform high-level administrative and maintenance/utility
operations on a Db2 instance or database; privileges convey the right
to perform certain actions against specic database objects (like
tables, indexes, and views). The most common DCL statements are
GRANT and REVOKE.
z Data Denition Language (DDL) statements: Used to create, alter,
and delete individual database objects. The DDL statements that are
used the most are
CREATE, ALTER, and DROP.
z Data Manipulation Language (DML) statements: Used
exclusively to store data in, modify data in, remove data from, and
obtain data from select tables and/or views. The most common DML
statements used are
INSERT, UPDATE, DELETE, and SELECT.
z Transaction Management statements: Used to establish and
terminate database connections and transactions. A transaction
(also known as a unit of work) is a sequence of one or more SQL
operations that are grouped together as a single unit. Such a unit is
considered atomic (from the Greek word meaning “not able to be
cut”) because it is indivisible: either all of a transaction’s work is
carried out, or none of its operations performed are made permanent.
The transaction management statements that are recognized by Db2
are
CONNECT, ROLLBACK, and COMMIT.
One of the simplest ways to construct applications that require SQL is
to use a methodology known as embedded SQL programming. As the name
implies, embedded SQL applications are built by coding SQL statements
directly into high-level programming language source code les.
Unfortunately, this approach has some drawbacks. For one thing, high-
level programming language compilers do not recognize, and therefore
cannot interpret, SQL statements. And, some RDBMS engines cannot work
directly with high-level programming language variables: instead, special
variables known as host variables must be used to move data between
an application and the RDBMS engine. (This is the case with Db2.)
Therefore, source code les containing embedded SQL statements must be
preprocessed with an SQL precompiler before they can be compiled.
Note: Db2 ships with an SQL precompiler that will
convert SQL statements found in a source code file
into comments and generate appropriate runtime
API calls to replace them. It also evaluates the data
types of declared host variables and determines which data
conversion methods are needed to move data in and out of those
variables.
Furthermore, embedded SQL applications lack interoperability. Because
RDBMS vendors do not strictly adhere to SQL language standards,
embedded SQL applications developed for one RDBMS will, in all
likelihood, have to be modied before they can be used with another.
Fortunately, there is another way to construct applications that
must perform SQL operations. And, while the process may not be as
straightforward as embedding SQL statements in a source code le, it is
almost as simple.