Enabling Before-images During Table Creation

Learn how to enable before-images while creating a table.

You can create a table with an optional clause to enable the generation and persistent storage of before-images.

Syntax:

before_image_definition ::= ENABLE BEFORE IMAGE [ttl_definition]

Semantics

The ENABLE BEFORE IMAGE clause generates before-images for table rows for subsequent update and delete operations. For insert operations, before-images will be empty. In addition to enabling before-images while creating the table, you must also enable before-images in the subscription configuration through the Streams API. For more details, see Using NoSQLSubscriptionConfig in the Streams Developer’s Guide.

If you don’t include the ENABLE BEFORE IMAGE clause, the subscribed table can only stream after-images.

To enable before-images generation after the table is created, you must use the ALTER TABLE Statement with an ENABLE BEFORE IMAGE clause.

To limit the storage consumed by before-images, you can use a TTL definition to expire the before-images. The TTL value indicates that the before-images are stored on the disk from the time the before-images are generated until the TTL expires. After this duration, the before-images expire, freeing up the disk space they consumed, and will not appear in the stream.

If you don’t supply a TTL definition for before-images, the generated before-images remain for 24 hours.

Note:

Example 1 - Enable before-images while creating airline baggage tracking application table

CREATE TABLE BaggageInfo (ticketNo LONG,
fullName STRING,
gender STRING,
contactPhone STRING,
confNo STRING,
bagInfo JSON,
PRIMARY KEY (ticketNo)
)USING TTL 5 DAYS ENABLE BEFORE IMAGE USING TTL 48 HOURS

Explanation:The CREATE TABLE statement above creates a BaggageInfo table and enables before-images generation for any subsequent DML operations. The TTL value for table data is set to 5 days. The TTL value for before-images is set to 48 hours.