Creating and modifying DB2 objects from application
programs
Your application program can create and manipulate DB2® objects, such as tables, views,
triggers, distinct types, user-defined functions, and stored procedures.
You must have the appropriate authorizations to create such objects.
Creating tables
Creating a table provides a logical place
to store related data on a DB2 subsystem.
Providing a unique key for a table
Use ROWID columns or identity columns to store unique values
for each row in a table.
Fixing tables with incomplete definitions
If a table has an incomplete definition, you
cannot load the table, insert data, retrieve data, update data, or
delete data. You can however drop the table, create the primary index,
and drop or create other indexes.
Dropping tables
When you drop a table, you delete the data
and the table definition. You also delete all synonyms, views, indexes,
referential constraints, and check constraints that are associated
with that table.
Defining a view
A view is a named specification of a result
table. Use views to control which users have access to certain data
or to simplify writing SQL statements.
Dropping a view
When you drop a view, you also drop all views that are
defined on that view. The base table is not affected.
Creating a common table expression
Creating a common table expression saves you the overhead
of creating and dropping a regular view that you need to use only
once. Also, during statement preparation, DB2 does not need to access the catalog for the
view, which saves you additional overhead.
Creating a trigger
A trigger is a set of SQL statements that execute when a
certain event occurs in a table or view. Use triggers to control changes in DB2 databases. Triggers are more powerful than
constraints because they can monitor a broader range of changes and perform a broader range of
actions.
Sequence objects
A sequence is a user-defined object that generates
a sequence of numeric values according to the specification with which
the sequence was created. Sequences, unlike identity columns, are
not associated with tables. Applications refer to a sequence object
to get its current or next value.
DB2 object relational extensions
With the object extensions of DB2 ,
you can incorporate object-oriented concepts and methodologies into
your relational database by extending DB2 with
richer sets of data types and functions.
Creating a distinct type
Distinct types are useful when you want DB2 to handle certain data differently than other
data of the same data type. For example, even though all currencies
can be declared as type DECIMAL, you do not want euros to be compared
to Japanese yen.
Creating a user-defined function
You can extend the SQL functionality of DB2 by adding your own or third party vendor
function definitions.
Creating a stored procedure
A stored procedure is
executable code that can be called by other programs. The
process for creating one depends on the type of procedure.