Syntax options:
AUTOMATIC AS value-expr | AUTOMATIC INSERT AS value-expr |
AUTOMATIC UPDATE AS value-expr
These AUTOMATIC column clauses allow you to store special
information when data is inserted into a row or a row is updated.
For example, you can log application-specific information to
audit activity or provide essential values, such as time stamps
or unique identifiers for the data.
The assignment of values to these types of columns is managed by
Oracle Rdb. The AUTOMATIC INSERT clause can be used to provide
a complex default for the column when the row is inserted; it
cannot be changed by an UPDATE statement. The AUTOMATIC UPDATE
clause can be used to provide an updated value during an UPDATE
statement. The AUTOMATIC clause is the default and specifies that
the value expression should be applied during both INSERT and
UPDATE statements. The column type is derived from the AS value-
expr; using CAST allows a specific data type to be specified.
However, this is not required and is rarely necessary.
You can define an AUTOMATIC INSERT column to automatically
receive data during an insert operation. The data is stored like
any other column, but the column is read-only. Because AUTOMATIC
columns are treated as read-only columns, they cannot appear in
the column list for an insert operation nor be modified by an
update operation. AUTOMATIC UPDATE columns can have an associated
default value that will be used when the row is inserted.
Suppose that you want to store the current time stamp of a
transaction and supply a unique numeric value for an order
number. In addition, when the row is updated (the order is
altered), you want a new time stamp to be written to the LAST_
UPDATED column. You could write an application to supply this
information, but you could not guarantee the desired behavior.
For instance, a user with access to the table might update
the table with interactive SQL and forget to enter a new time
stamp to the LAST_UPDATED column. If you use an AUTOMATIC column
instead, it can be defined so that columns automatically receive
data during an insert operation. The data is stored like any
other column, but the column is read-only.