Requirements
To add table retention policies, you must haveALTER and DELETE privileges for the system and the specific table.
In addition, a database table must meet these conditions to support retention policies:
- Have a designated column (For details, see TimeKeys and Clustering Keys)
- Be a user-created table or system-persistent table. You cannot edit virtual system tables.
Table Retention Properties
Table retention properties define the specific parameters that control how long data remains in a table before being automatically deleted. These properties determine both the duration of retention and the granularity at which the system evaluates data for removal, ensuring that retention policies operate consistently and predictably. By configuring these properties, you can fine-tune how the system balances data availability with storage efficiency.Table Retention and TimeKey
Retention policies of a table are directly linked to the column defined as the TimeKey of the table. For each row in the table, the TimeKey column represents its age, which the system evaluates to determine whether to retain or delete the row. Table retention policies cannot function properly if the TimeKey column does not represent the age of each row. Additionally, the TimeKey bucket value also represents the frequency of evaluating the age of each row in the table. For example, a table with a TimeKey bucket of1 HOUR and a retention period of 1 DAY would evaluate each row every hour to determine if it is more than one day old.
Based on the TimeKey bucket frequency for culling older records, the system can potentially retain a row for slightly longer than the set period of a retention policy, up to a maximum retention time of the sum of the retention period and the TimeKey bucket.
The table retention policy also deletes older rows of any dependent global dictionary compression tables defined on columns of the original table.
Table Retention Tasks
The system deletes older records as a distributed task, which is visible in the sys.tasks and sys.subtasks catalog tables. Additionally, each table retention policy creates a scheduled process, which is visible in the sys.tkt_table_info system catalog table. For details, see Distributed Tasks.Retention and Workload Management
Retention policies execute periodically to delete data in two separate phases: a truncate operation and a delete operation. The truncate operation interfaces directly with the storage layer of the system and is not affected by any workload management configuration. In contrast, the delete operation runs as aDELETE SQL statement and uses a designated Retention Policy service class for retention policies. This service class is a built-in class that administrative users can edit. All table retention policies use the same service class.
Default Retention Policies
A subset of persistent system tables has table retention policies set by default. All retention policies in the system, including those set by default, are visible in the System Catalog. You can also view a retention policy for an individual table by executing an EXPORT TABLE statement.Add Retention Policies to Tables
You can add table retention policies using aCREATE TABLE or ALTER TABLE SQL statement.
Table retention policies are optional for all user-defined tables. If a table lacks a retention policy, the default behavior is to retain data in perpetuity.
Retention policies follow this syntax as part of either a CREATE TABLE option or an ALTER TABLE statement.
SQL
| Parameter | Type | Description |
|---|---|---|
retention_granularity | numeric | A number that represents the amount of time before the system deletes data in the table. You must pair this number with a specific time type, represented by the retention_value. |
retention_value | string | The unit of time that represents how long the table retains data. Supported values are: [ WEEK, DAY, HOUR, MINUTE, SECOND, MILLISECOND ]For example, 1 DAY schedules the table retention to a granularity of one day. |
RETENTION POLICY AGE 1 DAY. The retention policy depends on the created_at column because it is the TimeKey column. The TimeKey bucket value (1, HOUR) determines how frequently the system checks for any rows to remove.
SQL

