---
metadata:
  - name: generator
    content: Diplodoc Platform v5.71.0
alternate:
  - https://ydb.tech/docs/en/yql/reference/syntax/create_table/with.md?version=v26.3
  - https://ydb.tech/docs/ru/yql/reference/syntax/create_table/with.md?version=v26.3
  - href: https://ydb.tech/docs/en/yql/reference/syntax/create_table/with.md?version=v26.3
    type: text/markdown
    title: Markdown version
  - href: https://ydb.tech/docs/en/llms.txt?revision=3d20fc614f8b1a092ebb766518e1c746cda9c005&version=v26.3
    rel: describedby
sourcePath: en/core/yql/reference/syntax/create_table/with.md
---
> **Documentation capabilities:** Search, read sources, and browse this documentation: [agent guide](https://ydb.tech/docs/docs-api/agent/overview?project=ydb-platform--ydb&lang=en&version=v26.3).

> **Documentation Index:** Fetch the complete configuration index at https://ydb.tech/docs/en/llms.txt?revision=3d20fc614f8b1a092ebb766518e1c746cda9c005&version=v26.3

# Additional parameters (WITH)

You can also specify a number of YDB-specific parameters for the table. When you create a table, those parameters are listed in the ```WITH``` clause:

```yql
CREATE TABLE table_name (...)
WITH (
    key1 = value1,
    key2 = value2,
    ...
)
```

Here, `key` is the name of the parameter and `value` is its value.

The list of allowable parameter names and their values is provided on the table description page [YDB](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=v26.3).

For example, such a query will create a string table with automatic partitioning enabled based on partition size and a preferred size of each partition being 512 megabytes:

```yql
CREATE TABLE my_table (
    id Uint64,
    title Utf8,
    PRIMARY KEY (id)
)
WITH (
    AUTO_PARTITIONING_BY_SIZE = ENABLED,
    AUTO_PARTITIONING_PARTITION_SIZE_MB = 512
);
```


A column-oriented table is created using the `STORE = COLUMN` parameter in the `WITH` clause:

```sql
 CREATE TABLE table_name (
    a Uint64 NOT NULL,
    b Timestamp NOT NULL,
    c Float,
    PRIMARY KEY (a, b)
  )
  PARTITION BY HASH(b)
  WITH (
    STORE = COLUMN
  );
```

The properties and capabilities of columnar tables are described in the article [Table](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=v26.3), and the specifics of their creation through YQL are described on the page [CREATE TABLE](https://ydb.tech/docs/en/yql/reference/syntax/create_table/index.md?version=v26.3).

## Time to Live (TTL) {#time-to-live}

In the `WITH` clause, you can set TTL (Time to Live), the lifetime of a row in a row-oriented or column-oriented table. [TTL](https://ydb.tech/docs/en/concepts/ttl.md?version=v26.3) automatically deletes rows or evicts them to external storage after the specified number of seconds has elapsed since the time recorded in the TTL column. You can set TTL when creating a row-oriented or column-oriented table, or add it later using [`ALTER TABLE`](https://ydb.tech/docs/en/yql/reference/syntax/alter_table/set.md?version=v26.3).

For a column-oriented table, the TTL column must be the first column of the primary key or have a [min_max index](https://ydb.tech/docs/en/yql/reference/syntax/create_table/min_max_index.md?version=v26.3).

The short form of the TTL value for specifying the time to delete rows:

```yql
Interval("<literal>") ON column [AS <unit>]
```

The general form of the TTL value:

```yql
Interval("<literal1>") action1, ..., Interval("<literalN>") actionN ON column [AS <unit>]
```

* `action` — the action performed when the TTL expression triggers. Allowed values:
    * `DELETE` — delete the row;
    * `TO EXTERNAL DATA SOURCE <path>` — evict the row to external storage specified by the [external data source](https://ydb.tech/docs/en/concepts/datamodel/external_data_source.md?version=v26.3) at the path `<path>`.
* `<unit>` — the unit of measurement, specified only for columns with a [numeric type](https://ydb.tech/docs/en/concepts/ttl.md?version=v26.3#restrictions):
    * `SECONDS`;
    * `MILLISECONDS`;
    * `MICROSECONDS`;
    * `NANOSECONDS`.

Example of creating a row-oriented and column-oriented tables with TTL:

{% list tabs %}

- Creating row-oriented table with TTL

    ```sql
    CREATE TABLE my_table (
        id Uint64,
        title Utf8,
        expire_at Timestamp,
        PRIMARY KEY (id)
    )
    WITH (
        TTL = Interval("PT0S") ON expire_at
    );
    ```

- Creating column-oriented table with TTL

    ```sql
    CREATE TABLE table_name (
        a Uint64 NOT NULL,
        b Timestamp NOT NULL,
        c Float,
        INDEX idx_b_min_max LOCAL USING min_max ON (b),
        PRIMARY KEY (a, b)
    )
    PARTITION BY HASH(b)
    WITH (
        STORE = COLUMN,
        TTL = Interval("PT0S") ON b
    );
    ```

{% endlist %}

Example of creating a column-oriented table with eviction to external storage:

<!-- source: en/_includes/not_allow_for_oltp_note.md -->
{% note warning %}

<!-- source: en/_includes/not_allow_for_oltp_text.md -->
Supported only for [column-oriented](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=v26.3#column-oriented-tables) tables. Support for [row-oriented](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=v26.3#row-oriented-tables) tables is currently under development.
<!-- endsource: en/_includes/not_allow_for_oltp_text.md -->

{% endnote %}
<!-- endsource: en/_includes/not_allow_for_oltp_note.md -->

```yql
CREATE TABLE table_name (
    a Uint64 NOT NULL,
    b Timestamp NOT NULL,
    c Float,
    INDEX idx_b_min_max LOCAL USING min_max ON (b),
    PRIMARY KEY (a, b)
)
PARTITION BY HASH(b)
WITH (
    STORE = COLUMN,
    TTL =
        Interval("P1D") TO EXTERNAL DATA SOURCE `/Root/s3`,
        Interval("P2D") DELETE
    ON b
);
```

