---
title: CREATE STREAMING TABLE (pipelines)
description: Create a streaming table in Lakeflow pipelines SQL with the `CREATE STREAMING TABLE` statement, backed by a pipeline for incremental data processing.
canonical_url: https://docs.databricks.com/aws/en/ldp/developer/ldp-sql-ref-create-streaming-table
---

# CREATE STREAMING TABLE (pipelines)

A *[streaming table](https://docs.databricks.com/aws/en/ldp/concepts/streaming-tables.md)* is a table with support for streaming or incremental data processing. Streaming tables are backed by pipelines. Each time an streaming table is refreshed, its flows process new data from the source tables. Append flows add rows to the streaming table, and AUTO CDC and REPLACE flows update or replace existing rows. You can refresh streaming tables manually or on a schedule.

To learn more about how to perform or schedule refreshes, see [Run a pipeline update](https://docs.databricks.com/aws/en/ldp/updates.md).

## Syntax

```
CREATE [OR REFRESH] [PRIVATE] STREAMING TABLE
  table_name
  [ table_specification ]
  [ table_clauses ]
  [ {flow_clause | AS query} ]

table_specification
  ( { column_identifier column_type [column_properties] } [, ...]
    [ column_constraint ] [, ...]
    [ , table_constraint ] [...] )

   column_properties
      { NOT NULL | GENERATED ALWAYS AS ( expr ) | GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( [ START WITH start | INCREMENT BY step ] [ ...] ) ] | DEFAULT default_expression | COMMENT column_comment | column_constraint | MASK clause } [ ... ]

table_clauses
  { USING DELTA
    PARTITIONED BY (col [, ...]) |
    CLUSTER BY clause |
    LOCATION path |
    COMMENT view_comment |
    TBLPROPERTIES clause |
    WITH { ROW FILTER clause } } [ ... ]
   } [ ... ]

flow_clause
  FLOW { { INSERT [ONCE] BY NAME query } |
  { AUTO CDC auto_cdc_flow_spec } |
  { AUTO CDC [ONCE] auto_cdc_from_snapshot_spec } |
  { REPLACE WHERE predicate BY NAME query } |
  { REPLACE USING ( column_name [, ...] ) SEQUENCE BY sequence_column BY NAME query } }

auto_cdc_from_snapshot_spec
  FROM SNAPSHOT ( snapshot_query )
  [ WITH VERSION ( version_query ) ]
  KEYS ( key [, ...] )
  [ STORED AS { SCD TYPE 1 | SCD TYPE 2 } ]
  [ TRACK HISTORY ON { ( col_list ) | * EXCEPT ( col_list ) } ]
```

## Parameters

* **REFRESH**

  If specified, creates the table, or updates an existing table and its content.

* **PRIVATE**

  Creates a private streaming table.

  * They are not added to the catalog and are only accessible within the defining pipeline
  * They can have the same name as an existing object in the catalog. Within the pipeline, if a private streaming table and an object in the catalog have the same name, references to the name resolve to the private streaming table.
  * Private streaming tables are only persisted across the lifetime of the pipeline, not just a single update.

  Private streaming tables were previously created with the `TEMPORARY` parameter.

* **table\_name**

  The name of the newly created table. The fully qualified table name must be unique.

* **table\_specification**

  This optional clause defines the list of columns, their types, properties, descriptions, and column constraints.

  * **[column\_identifier](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md#column-alias)**

    The column names must be unique and map to the output columns of the query.

  * **[column\_type](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-datatypes.md)**

    Specifies the column's data type. Not all data types supported by Databricks are supported by streaming tables.

  * **column\_comment**

    An optional `STRING` literal describing the column. This option must be specified along with `column_type`. If the column type is not specified, the column comment is skipped.

  * **GENERATED ALWAYS AS ( [expr](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-expression.md) )**

    When you specify this clause the value of this column is determined by the specified `expr`.

    The `DEFAULT COLLATION` of the table must be `UTF8_BINARY`.

    `expr` may be composed of literals, column identifiers within the table, and deterministic, built-in SQL functions or operators except:

    * [Aggregate functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-functions-builtin.md#aggregate-functions)
    * [Analytic window functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-functions-builtin.md#analytic-window-functions)
    * [Ranking window functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-functions-builtin.md#ranking-window-functions)
    * Table valued generator functions
    * Columns with a collation other than `UTF8_BINARY`

    Also `expr` must not contain any [subquery](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-query.md).

  * **GENERATED \{ ALWAYS | BY DEFAULT } AS IDENTITY \[ ( \[ START WITH start ] \[ INCREMENT BY step ] ) ]**

    **Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 10.4 LTS and above

    Defines an identity column. When you write to the table, and do not provide values for the identity column, it will be automatically assigned a unique and statistically increasing (or decreasing if `step` is negative) value. This clause is only supported for Delta tables. This clause can only be used for columns with BIGINT data type.

    The automatically assigned values start with `start` and increment by `step`. Assigned values are unique but are not guaranteed to be contiguous. Both parameters are optional, and the default value is 1. `step` cannot be `0`.

    If the automatically assigned values are beyond the range of the identity column type, the query will fail.

    When `ALWAYS` is used, you cannot provide your own values for the identity column.

    The following operations are not supported:

    * `PARTITIONED BY` an identity column
    * `UPDATE` an identity column

    > [!NOTE]
    >
    > Declaring an identity column on a table disables concurrent transactions. Only use identity columns in use cases where concurrent writes to the target table are not required.

  * **DEFAULT default\_expression**

    **Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 11.3 LTS and above

    Defines a `DEFAULT` value for the column which is used on `INSERT`, `UPDATE`, and `MERGE ... INSERT` when the column is not specified.

    If no default is specified `DEFAULT NULL` is applied for nullable columns.

    `default_expression` may be composed of literals, and built-in SQL functions or operators except:

    * [Aggregate functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-functions-builtin.md#aggregate-functions)
    * [Analytic window functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-functions-builtin.md#analytic-window-functions)
    * [Ranking window functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-functions-builtin.md#ranking-window-functions)
    * Table valued generator functions

    Also `default_expression` must not contain any [subquery](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-query.md).

    `DEFAULT` is supported for `CSV`, `JSON`, `PARQUET`, and `ORC` sources.

  * **[column\_constraint](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-table-constraint.md)**

    Adds an informational primary key or informational foreign key constraint to the column in a streaming table.

  * **[MASK clause](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-column-mask.md)**

    Adds a column mask function to anonymize sensitive data.

    See [Row filters and column masks](https://docs.databricks.com/aws/en/data-governance/unity-catalog/filters-and-masks/index.md).

  * **CONSTRAINT expectation\_name EXPECT (expectation\_expr) \[ ON VIOLATION \{ FAIL UPDATE | DROP ROW } ]**

    Adds data quality expectations to the streaming table. These data quality expectations can be tracked over time and accessed through the streaming table's [event log](https://docs.databricks.com/aws/en/sql/language-manual/functions/event_log.md). A `FAIL UPDATE` expectation causes the processing to fail when both creating the table as well as refreshing the table. A `DROP ROW` expectation causes the entire row to be dropped if the expectation is not met. See [Manage data quality with pipeline expectations](https://docs.databricks.com/aws/en/ldp/expectations.md).

    `expectation_expr` may be composed of literals, column identifiers within the table, and deterministic, built-in SQL functions or operators except:

    * [Aggregate functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-functions-builtin.md#aggregate-functions)
      * [Analytic window functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-functions-builtin.md#analytic-window-functions)
      * [Ranking window functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-functions-builtin.md#ranking-window-functions)
      * Table valued generator functions

    Also `expr` must not contain any [subquery](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-query.md).

* **table\_constraint**

  When specifying a schema, you can define primary and foreign keys. The constraints are informational and are not enforced. See the [CONSTRAINT clause](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-table-constraint.md) in the SQL language reference.

  > [!NOTE]
  >
  > To define table constraints, your pipeline must be a Unity Catalog-enabled pipeline.

* **table\_clauses**

  Optionally specify partitioning, comments, and user defined properties for the table. Each sub clause may only be specified once.

  * **USING DELTA**

    Specifies the data format. The only option is DELTA.

    This clause is optional, and defaults to DELTA.

  * **PARTITIONED BY**

    An optional list of one or more columns to use for partitioning in the table. Mutually exclusive with `CLUSTER BY`.

    Liquid clustering provides a flexible, optimized solution for clustering. Consider using `CLUSTER BY` instead of `PARTITIONED BY` for pipelines.

  * **CLUSTER BY**

    Enable liquid clustering on the table and define the columns to use as clustering keys. Use automatic liquid clustering with `CLUSTER BY AUTO`, and Databricks intelligently chooses clustering keys to optimize query performance. Mutually exclusive with `PARTITIONED BY`.

    See [Use liquid clustering for tables](https://docs.databricks.com/aws/en/tables/clustering.md).

  * **LOCATION**

    An optional storage location for table data. If not set, the system defaults to the pipeline storage location.

    This option is only available when publishing to Hive metastore. In Unity Catalog, the location is managed automatically.

  * **COMMENT**

    An optional `STRING` literal to describe the table.

  * **TBLPROPERTIES**

    An optional list of [table properties](https://docs.databricks.com/aws/en/ldp/properties.md) for the table.

  * **WITH ROW FILTER**

  Adds a row filter function to the table. Future queries for that table receive a subset of the rows for which the function evaluates to TRUE. This is useful for fine-grained access control, because it allows the function to inspect the identity and group memberships of the invoking user to decide whether to filter certain rows.

  See [`ROW FILTER` clause](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-row-filter.md).

  * **FLOW**

    Optionally defines a [flow](https://docs.databricks.com/aws/en/ldp/concepts/flows.md) inline with the table creation. A flow is a stateful query that refreshes the contents of the table. If `FLOW` is not specified, you can use `AS query` instead, or define flows separately with [`CREATE FLOW`](https://docs.databricks.com/aws/en/ldp/developer/ldp-sql-ref-create-flow.md). You can specify one of the following flow types:

    * **INSERT BY NAME**

      Inserts data into the table by column name. If the `ONCE` option is not supplied, the query must be a streaming query. Use the `STREAM` keyword to use streaming semantics to read from the source. If the read encounters a change or deletion to an existing record, an error is thrown. It is safest to read from static or append-only sources.

      > [!NOTE]
      >
      > `FLOW INSERT BY NAME` is equivalent to using `AS query`. The following two statements have identical behavior:
      >
      > ```sql
      > CREATE OR REFRESH STREAMING TABLE raw_data
      > AS SELECT * FROM STREAM read_files('/Volumes/catalog/schema/landing/my_path');
      >
      > CREATE OR REFRESH STREAMING TABLE raw_data
      > FLOW INSERT BY NAME SELECT * FROM STREAM read_files('/Volumes/catalog/schema/landing/my_path');
      > ```

    * **ONCE**

      Optionally defines the flow as a one-time flow, such as a backfill. When `ONCE` is supplied, the query is not a streaming query, and the flow runs one time by default. If the table is refreshed with a full refresh, the `ONCE` flow runs again to recreate the data. `ONCE` applies to `INSERT BY NAME` and `AUTO CDC ... FROM SNAPSHOT` flows.

      For an `AUTO CDC ... FROM SNAPSHOT` flow with `WITH VERSION`, each update processes versions in order until the version query returns no rows. The `ONCE` and non-`ONCE` cases differ in what happens on later updates:

      * **Without `ONCE`:** the flow runs on every update. Each update processes any new versions, then returns to `IDLE` until a later version appears or the table is fully refreshed.
      * **With `ONCE`:** the flow completes after its first successful snapshot commit and is skipped on later incremental updates. If its first version query returns no rows, no snapshot commits, so the flow stays eligible rather than completing. A full refresh runs it again.

    * **`AUTO CDC`**

      **Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 17.3 and above

      Defines an `AUTO CDC` flow that processes change data capture (CDC) records from a source into the table. Use `AUTO CDC` when the source data includes CDC semantics. See [The AUTO CDC APIs: Simplify change data capture with pipelines](https://docs.databricks.com/aws/en/ldp/cdc.md).

    * **`AUTO CDC ... FROM SNAPSHOT`**

      Defines an inline `AUTO CDC` flow that derives changes by comparing snapshots instead of reading a change feed. Use this form when change data capture is not enabled on the source and only full snapshots are available. The source is specified with a required `FROM SNAPSHOT (snapshot_query)` clause and an optional `WITH VERSION (version_query)` clause. This embedded flow is anonymous, is owned by the streaming table, and has no `INTO target` clause. It accepts the same `ONCE`, `FROM SNAPSHOT (...)`, `WITH VERSION (...)`, `KEYS`, `STORED AS`, and `TRACK HISTORY ON` parameters as the standalone form. For full descriptions, see [CREATE FLOW (pipelines)](https://docs.databricks.com/aws/en/ldp/developer/ldp-sql-ref-create-flow.md). See also [How AUTO CDC FROM SNAPSHOT works](https://docs.databricks.com/aws/en/ldp/cdc.md#cdc-from-snapshot).

      The source must use the parenthesized `FROM SNAPSHOT (query)` form. To migrate an earlier single-identifier `FROM SNAPSHOT source`, rewrite it as `FROM SNAPSHOT (SELECT * FROM source)`.

    * **REPLACE WHERE [predicate](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-expression.md) BY NAME query**

      Defines a `REPLACE WHERE` flow that recomputes and overwrites only the rows matching `predicate`, leaving all other rows untouched. Use `REPLACE WHERE` for incremental batch processing of joins and aggregations, late-arriving data, schema evolution, and backfills. `BY NAME` is required. See [Batch processing with REPLACE WHERE flows](https://docs.databricks.com/aws/en/ldp/flows-replace-where.md).

    * **REPLACE USING ( [column\_name](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-identifiers.md) \[, ...] ) SEQUENCE BY sequence\_column BY NAME query**

      > [!NOTE]
      >
      > REPLACE USING flows require Databricks Runtime 18.2 and above.

      Defines a `REPLACE USING` flow that replaces all rows matching the specified key columns and leaves all other rows untouched. Use `REPLACE USING` when your source is a series of partial snapshots keyed by column. `SEQUENCE BY` orders the updates so the highest sequence for a key wins, even when updates arrive out of order. The source must be a streaming source. `BY NAME` is required. See [Partial snapshot replacement with REPLACE USING flows](https://docs.databricks.com/aws/en/ldp/flows-replace-using.md).

* **[AS query](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select.md)**

  This clause populates the table using the data from `query`. This query must be a **streaming** query. Use the STREAM keyword to use streaming semantics to read from the source. If the read encounters a change or deletion to an existing record, an error is thrown. It is safest to read from static or append-only sources. To ingest data that has change commits, you can add the `skipChangeCommits` read option to handle errors.

  When you specify a `query` and a `table_specification` together, the table schema specified in `table_specification` must contain all the columns returned by the `query`, otherwise you get an error. Any columns specified in `table_specification` but not returned by `query` return `null` values when queried.

  For more information on streaming data, see [Transform data with pipelines](https://docs.databricks.com/aws/en/ldp/transform.md).

  * **Read Options**

    You can specify read options in the query to configure how data is read from the source. For example, you can specify `skipChangeCommits` to skip over any change commits in the source data. Read options are specified as a map in the `WITH` clause of query. For example:

    ```sql
    SELECT * FROM STREAM source_table WITH (SKIPCHANGECOMMITS=TRUE, STARTINGVERSION=X)
    ```

    The `=TRUE` is optional, so you can also specify a boolean option like this:

    ```sql
    SELECT * FROM STREAM source_table WITH (SKIPCHANGECOMMITS)
    ```

    > [!NOTE]
    >
    > Read options are only supported for Databricks Runtime 17.3 and above.

    The below read options are supported for Delta, for details on each option, see [Delta Lake table streaming reads and writes](https://docs.databricks.com/aws/en/structured-streaming/delta-lake.md).

    * `maxFilesPerTrigger`
    * `maxBytesPerTrigger`
    * `startingVersion`
    * `startingTimestamp`
    * `readChangeFeed`
    * `withEventTimeOrder`
    * `skipChangeCommits`

## Required permissions

The run-as user for a pipeline must have the following permissions:

* `SELECT` privilege over the base tables referenced by the streaming table.
* `USE CATALOG` privilege on the parent catalog and the `USE SCHEMA` privilege on the parent schema.
* `CREATE MATERIALIZED VIEW` privilege on the schema for the streaming table.

For a user to be able to update the pipeline the streaming table is defined within, they require:

* `USE CATALOG` privilege on the parent catalog and the `USE SCHEMA` privilege on the parent schema.
* Ownership of the streaming table or `REFRESH` privilege on the streaming table.
* The owner of the streaming table must have the `SELECT` privilege over the base tables referenced by the streaming table.

For a user to be able to query the resulting streaming table, they require:

* `USE CATALOG` privilege on the parent catalog and the `USE SCHEMA` privilege on the parent schema.
* `SELECT` privilege over the streaming table.

## Limitations

* Only table owners can refresh streaming tables to get the latest data.
* `ALTER TABLE` commands are disallowed on streaming tables. The definition and properties of the table should be altered through the `CREATE OR REFRESH` or [ALTER STREAMING TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-alter-streaming-table.md) statement.
* Evolving the table schema through DML commands like `INSERT INTO`, and `MERGE` is not supported.
* The following commands are not supported on streaming tables:
  * `CREATE TABLE ... CLONE <streaming_table>`
  * `COPY INTO`
  * `ANALYZE TABLE`
  * `RESTORE`
  * `TRUNCATE`
  * `GENERATE MANIFEST`
  * `[CREATE OR] REPLACE TABLE`
* Renaming the table or changing the owner is not supported.

## Examples

```sql
-- Define a streaming table from a volume of files:
CREATE OR REFRESH STREAMING TABLE customers_bronze
AS SELECT * FROM STREAM read_files("/databricks-datasets/retail-org/customers/*", format => "csv")

-- Define a streaming table from a streaming source table:
CREATE OR REFRESH STREAMING TABLE customers_silver
AS SELECT * FROM STREAM(customers_bronze)

-- Use automatic liquid clustering to let Databricks choose the clustering columns:
CREATE OR REFRESH STREAMING TABLE customers_bronze_auto
CLUSTER BY AUTO
AS SELECT * FROM STREAM read_files("/databricks-datasets/retail-org/customers/*", format => "csv")

-- Define a table with a row filter and column mask:
CREATE OR REFRESH STREAMING TABLE customers_silver (
  id int COMMENT 'This is the customer ID',
  name string,
  region string,
  ssn string MASK catalog.schema.ssn_mask_fn COMMENT 'SSN masked for privacy'
)
WITH ROW FILTER catalog.schema.us_filter_fn ON (region)
AS SELECT * FROM STREAM(customers_bronze)

-- Define a streaming table with an identity column:
CREATE OR REFRESH STREAMING TABLE customers_with_id (
  customer_id BIGINT GENERATED ALWAYS AS IDENTITY,
  name string,
  region string
)
AS SELECT name, region FROM STREAM(customers_bronze)

-- Define a streaming table that you can add flows into:
CREATE OR REFRESH STREAMING TABLE orders;

-- Define a streaming table with an inline append flow:
CREATE OR REFRESH STREAMING TABLE raw_data
FLOW INSERT BY NAME SELECT * FROM STREAM read_files('/Volumes/catalog/schema/landing/my_path');

-- Define a streaming table with an inline AUTO CDC flow:
CREATE OR REFRESH STREAMING TABLE target
FLOW AUTO CDC
FROM stream(cdc_data.users)
KEYS (userId)
SEQUENCE BY sequenceNum
STORED AS SCD TYPE 1;

-- Define a streaming table with an inline REPLACE USING flow that keeps the latest
-- row for each payment_id:
CREATE OR REFRESH STREAMING TABLE payments_current
FLOW REPLACE USING (payment_id) SEQUENCE BY payment_date BY NAME
SELECT payment_id, booking_id, status, payment_date
FROM STREAM(samples.wanderbricks.payments);

-- Define a streaming table with an inline AUTO CDC FROM SNAPSHOT flow that processes
-- each new snapshot version on every update, using WITH VERSION to pick the next one:
CREATE STREAMING TABLE users
FLOW AUTO CDC
FROM SNAPSHOT (
  SELECT * FROM read_files('/Volumes/catalog/schema/landing/users/', format => 'json')
  WHERE _metadata.file_path = (SELECT version.path FROM current_snapshot_version())
)
WITH VERSION (
  SELECT struct(modification_time, path) AS version
  FROM list_files('/Volumes/catalog/schema/landing/users/')
  WHERE (
    NOT EXISTS (SELECT 1 FROM last_snapshot_version())
    OR struct(modification_time, path) > (SELECT version FROM last_snapshot_version())
  )
  ORDER BY modification_time, path
  LIMIT 1
)
KEYS (user_id)
STORED AS SCD TYPE 1;

-- Define a streaming table with an inline one-shot AUTO CDC FROM SNAPSHOT backfill:
CREATE STREAMING TABLE customers
FLOW AUTO CDC ONCE
FROM SNAPSHOT (SELECT * FROM catalog.schema.customers_snapshot)
KEYS (customer_id)
STORED AS SCD TYPE 1;
```
