---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://ydb.tech/docs/en/yql/reference/syntax/create_table.md?version=v25.4
  - https://ydb.tech/docs/ru/yql/reference/syntax/create_table.md?version=v25.4
  - href: en/yql/reference/syntax/create_table/index.md
    type: text/markdown
    title: Markdown version
  - href: ../../../../llms.txt
    type: text/markdown
    title: llms.txt
sourcePath: en/core/yql/reference/syntax/create_table/index.md
---
> **Documentation Index:** Fetch the complete configuration index at https://ydb.tech/docs/en/llms.txt

# CREATE TABLE

## CREATE TABLE syntax


The invocation of `CREATE TABLE` creates a [table](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=v25.4) with the specified data schema and primary key columns (`PRIMARY KEY`). It also allows defining secondary indexes on the created table.



```yql
CREATE TABLE [IF NOT EXISTS] <table_name> (
  [<column_name> <column_data_type>] [FAMILY <family_name>] [NULL | NOT NULL] [DEFAULT <default_value>]
  [COMPRESSION([algorithm=<algorithm_name>[, level=<value>]])]
  [, ...],
    INDEX <index_name>
      [GLOBAL]
      [SYNC|ASYNC]
      [USING <index_type>]
      ON ( <index_columns> )
      [COVER ( <cover_columns> )]
      [WITH ( <parameter_name> = <parameter_value>[, ...])]
    [, ...]
  PRIMARY KEY ( <column>[, ...]),
  [FAMILY <column_family> ( family_options[, ...])]
)
[PARTITION BY HASH ( <column>[, ...])]
[WITH (<setting_name> = <setting_value>[, ...])]

[AS SELECT ...]
```




YDB supports two types of tables:

* [Row-oriented](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=v25.4#row-oriented-tables) tables.
* [Column-oriented](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=v25.4#column-oriented-tables) tables.

The table type is specified by the `STORE` parameter in the `WITH` clause, where `ROW` indicates a [row-oriented](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=v25.4#row-oriented-tables) table and `COLUMN` indicates a [column-oriented](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=v25.4#column-oriented-tables) table:

```yql
CREATE <table_name> (
  columns
  ...
)
WITH (
  STORE = COLUMN -- Default value ROW
)
```

By default, if the `STORE` parameter is not specified, a row-oriented table is created.


{% note info %}

When choosing a name for the table, consider the common [schema object naming rules](https://ydb.tech/docs/en/concepts/datamodel/cluster-namespace.md?version=v25.4#object-naming-rules).

{% endnote %}

## Examples of table creation {#examples-tables-creation}

{% list tabs %}

- Creating a row-oriented table


    ```yql
    CREATE TABLE <table_name> (
      a Uint64,
      b Uint64,
      c Float,
      PRIMARY KEY (a, b)
    );
    ```



  For both key and non-key columns, only [primitive](https://ydb.tech/docs/en/yql/reference/types/primitive.md?version=v25.4) data types are allowed.



  Without additional modifiers, a column acquires an [optional](https://ydb.tech/docs/en/yql/reference/types/optional.md?version=v25.4) type and allows `NULL` values. To designate a non-optional type, use the `NOT NULL` constraint.



  Specifying a `PRIMARY KEY` with a non-empty list of columns is mandatory. These columns become part of the key in the order they are listed.


  Example of creating a row-oriented table using partitioning options:

  ```yql
  CREATE TABLE <table_name> (
    a Uint64,
    b Uint64,
    c Float,
    PRIMARY KEY (a, b)
  )
  WITH (
    AUTO_PARTITIONING_BY_SIZE = ENABLED,
    AUTO_PARTITIONING_PARTITION_SIZE_MB = 512
  );
  ```

  Such code will create a row-oriented table with automatic partitioning by partition size (`AUTO_PARTITIONING_BY_SIZE`) enabled, and with the preferred size of each partition (`AUTO_PARTITIONING_PARTITION_SIZE_MB`) set to 512 megabytes. The full list of row-oriented table partitioning options can be found in the [Partitioning Row-Oriented Tables](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=v25.4#partitioning) section.


- Creating a column-oriented table

  ```yql
  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
  );
  ```

  Example of creating a column-oriented table with an option to specify the minimum physical number of partitions for storing data:

  ```yql
  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,
    AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 10
  );
  ```

  This code will create a columnar table with 10 partitions. The full list of column-oriented table partitioning options can be found in the [Partitioning Column-Oriented Tables](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=v25.4#olap-tables-partitioning) section.

{% endlist %}



When creating row-oriented tables, it is possible to specify:

* [A secondary index](https://ydb.tech/docs/en/yql/reference/syntax/create_table/secondary_index.md?version=v25.4).
* [A vector index](https://ydb.tech/docs/en/yql/reference/syntax/create_table/vector_index.md?version=v25.4).
* [Column groups](https://ydb.tech/docs/en/yql/reference/syntax/create_table/family.md?version=v25.4).
* [Additional parameters](https://ydb.tech/docs/en/yql/reference/syntax/create_table/with.md?version=v25.4).

When creating column-oriented tables, it is possible to specify:

* [Column groups](https://ydb.tech/docs/en/yql/reference/syntax/create_table/family.md?version=v25.4).
* [Additional parameters](https://ydb.tech/docs/en/yql/reference/syntax/create_table/with.md?version=v25.4).

