---
title: CREATE STREAMING TABLE
description: Create a streaming table for incremental and streaming data processing with CREATE STREAMING TABLE in Databricks SQL.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-streaming-table
---

# CREATE STREAMING TABLE

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

Creates a *[streaming table](https://docs.databricks.com/aws/en/ldp/concepts/streaming-tables.md)*, a Delta table with extra support for streaming or incremental data processing.

Streaming tables are only supported in Lakeflow pipelines and on Databricks SQL with Unity Catalog. Running this command on supported Databricks Runtime compute only parses the syntax. See [Develop Lakeflow pipelines code with SQL](https://docs.databricks.com/aws/en/ldp/developer/sql-dev.md).

## Syntax

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

table_specification
  ( { column_identifier column_type [column_properties] } [, ...]
    [ CONSTRAINT expectation_name EXPECT (expectation_expr)
      [ ON VIOLATION { FAIL UPDATE | DROP ROW } ] ] [, ...]
    [ , 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
  { PARTITIONED BY (col [, ...]) |
    CLUSTER BY clause |
    COMMENT table_comment |
    DEFAULT COLLATION UTF8_BINARY |
    TBLPROPERTIES clause |
    schedule |
    WITH { ROW FILTER clause } } [...]

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

schedule
  { SCHEDULE [ REFRESH ] schedule_clause |
    TRIGGER ON UPDATE [ AT MOST EVERY trigger_interval ] }

schedule_clause
  { EVERY number { HOUR | HOURS | DAY | DAYS | WEEK | WEEKS } |
  CRON cron_string [ AT TIME ZONE timezone_id ]}
```

## <a id="parameters" />Parameters

* **REFRESH**

  If specified, refreshes the table with the latest data available from the sources defined in the query. Only new data that arrives before the query starts is processed. New data that gets added to the sources during the execution of the command is ignored until the next refresh. The refresh operation from CREATE OR REFRESH is fully declarative. If a refresh command does not specify all metadata from the original table creation statement, the unspecified metadata is deleted.

* **IF NOT EXISTS**

  Creates the streaming table if it does not exist. If a table by this name already exists, the `CREATE STREAMING TABLE` statement is ignored.

  You may specify at most one of `IF NOT EXISTS` or `OR REFRESH`.

* **[table\_name](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md#table-name)**

  The name of the table to be created. The name must not include a [temporal specification or options specification](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md#table-name).
  If the name is not qualified the table is created in the current schema.

* **table\_specification**

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

  If you do not define columns in the table schema you must specify `AS query`.

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

    A unique name for the column.

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

      Specifies the [data type](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-datatypes.md) of the column.

    * **NOT NULL**

      If specified the column does not accept `NULL` values.

    * **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.

    * **COMMENT column\_comment**

      A string literal to describe the column.

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

      Adds a primary key or foreign key constraint to the column in a streaming table.
      Constraints are not supported for tables in the `hive_metastore` catalog.

    * **[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. All subsequent queries from that column receive the result of evaluating that function over the column in place of the column's original value. This can be useful for fine-grained access control purposes where the function can inspect the identity or group memberships of the invoking user to decide whether to redact the value.

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

      Adds data quality expectations to the 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.

      If you omit `ON VIOLATION`, the expectation uses the default `warn` action. Violating rows are retained and the number of violations is recorded in the event log's [`ExpectationMetrics` object](https://docs.databricks.com/aws/en/ldp/monitor-event-log-schema.md#expectationmetrics).

      `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](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 constraints to a streaming table.
      Key constraints are not supported for tables in the `hive_metastore` catalog.

* **table\_clauses**

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

  * **[PARTITIONED BY](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-partition.md#partitioned-by)**

    An optional list of columns of the table to partition the table by.

    > [!NOTE]
    >
    > Liquid clustering provides a flexible, optimized solution for clustering. Consider using `CLUSTER BY` instead of `PARTITIONED BY` for streaming tables.

  * **[CLUSTER BY](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-cluster-by.md)**

    An optional clause to cluster by a subset of columns. Use automatic liquid clustering with `CLUSTER BY AUTO`, and Databricks intelligently chooses clustering keys to optimize query performance. See [Use liquid clustering for tables](https://docs.databricks.com/aws/en/tables/clustering.md).

    Liquid clustering cannot be combined with `PARTITIONED BY`.

  * **COMMENT table\_comment**

    A `STRING` literal to describe the table.

  * **DEFAULT COLLATION UTF8\_BINARY**

    **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.1 and above

    Forces the default collation of the streaming table to `UTF8_BINARY`.
    This clause is mandatory if the schema in which the table is created has a default collation other than `UTF8_BINARY`.
    The default collation of the streaming table is used as the default collation within the `query` and for column types.

  * **[TBLPROPERTIES](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-tblproperties.md#tblproperties)**

    Optionally sets one or more user defined properties.

    The `pipelines.channel` property, previously used to select a `PREVIEW` or `CURRENT` runtime channel, is no longer supported for standalone streaming tables and has no effect. Standalone streaming tables always run on the latest Databricks SQL runtime version. If an existing definition includes this property, it is safely ignored.

  * **schedule**

    <a id="schedule" />

    The schedule can either be a `SCHEDULE` statement or a `TRIGGER` statement.

    * **SCHEDULE \[ REFRESH ] schedule\_clause**

      * **`EVERY number { HOUR | HOURS | DAY | DAYS | WEEK | WEEKS }`**

        To schedule a refresh that occurs periodically, use `EVERY` syntax. If `EVERY` syntax is specified, the streaming table or materialized view is refreshed periodically at the specified interval based on the provided value, such as `HOUR`, `HOURS`, `DAY`, `DAYS`, `WEEK`, or `WEEKS`.
        The following table lists accepted integer values for `number`.

        | Time unit       | Integer value  |
        | --------------- | -------------- |
        | `HOUR or HOURS` | 1 \<= H \<= 72 |
        | `DAY or DAYS`   | 1 \<= D \<= 31 |
        | `WEEK or WEEKS` | 1 \<= W \<= 8  |

        > [!NOTE]
        >
        > The singular and plural forms of the included time unit are semantically equivalent.

      * **`CRON cron_string [ AT TIME ZONE timezone_id ]`**

        To schedule a refresh using a [quartz cron](http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html) value. Valid [time\_zone\_values](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-aux-conf-mgmt-set-timezone.md) are accepted. `AT TIME ZONE LOCAL` is not supported.

        The cron expression uses six space-separated fields in the order: `seconds minutes hours day-of-month month day-of-week`. Use `?` for either `day-of-month` or `day-of-week` to leave it unspecified.

        For example, `SCHEDULE CRON '0 0 0 * * ?' AT TIME ZONE 'UTC'` refreshes daily at midnight UTC.

        If `AT TIME ZONE` is absent, the session time zone is used.
        If `AT TIME ZONE` is absent and the session time zone is not set, an error is thrown.
        `SCHEDULE` is semantically equivalent to `SCHEDULE REFRESH`.

      The schedule can be provided as part of the `CREATE` command.
      Use [ALTER STREAMING TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-alter-streaming-table.md) or run `CREATE OR REFRESH` command with `SCHEDULE` clause to alter the schedule of a streaming table after creation.

    * **TRIGGER ON UPDATE \[ AT MOST EVERY trigger\_interval ]**

      Optionally set the table to refresh when an upstream data source is updated, at most once every minute. Set a value for `AT MOST EVERY` to require at least a minimum time between refreshes.

      The upstream data sources must be either external or managed Delta tables (including materialized views or streaming tables), or managed views whose dependencies are limited to supported table types.

      Enabling [file events](https://docs.databricks.com/aws/en/connect/unity-catalog/cloud-storage/manage-external-locations.md#file-events) can make triggers more performant, and increases some of the limits on trigger updates.

      The `trigger_interval` is an [INTERVAL](https://docs.databricks.com/aws/en/sql/language-manual/data-types/interval-type.md) statement that is at least 1 minute.

      `TRIGGER ON UPDATE` has the following limitations

      * No more than 10 upstream data sources per streaming table when using TRIGGER ON UPDATE.
      * Maximum of 1000 streaming tables or materialized views can be specified with TRIGGER ON UPDATE.
      * The `AT MOST EVERY` clause defaults to 1 minute, and cannot be less than 1 minute.

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

  Adds a row filter function to the table. All subsequent queries from that table receive a subset of the rows where the function evaluates to boolean TRUE. This can be useful for fine-grained access control purposes where the function can inspect the identity or group memberships of the invoking user to decide whether to filter certain rows.

* **FLOW**

  > [!NOTE]
  > **Beta**
  >
  > This feature is in [Beta](https://docs.databricks.com/aws/en/release-notes/release-types.md). Requires Databricks Runtime 17.3 and above.

  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. A separate `REFRESH STREAMING TABLE` statement lets you execute the flow. You can specify one of the following flow types:

  * **INSERT BY NAME**

    Inserts data into the table by column name. 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('abfss://my_path');
    >
    > CREATE OR REFRESH STREAMING TABLE raw_data
    > FLOW INSERT BY NAME SELECT * FROM STREAM read_files('abfss://my_path');
    > ```

  * **[AUTO CDC](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-streaming-table-auto-cdc.md)**

    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. `AUTO CDC` can also derive changes by comparing snapshots with the `FROM SNAPSHOT` form (in Beta). See [AUTO CDC FLOW Clause](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-streaming-table-auto-cdc.md).

  * **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 [REPLACE WHERE flows for standalone streaming tables](https://docs.databricks.com/aws/en/sql/mv-st/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. This can be achieved by adding the `STREAM` keyword to any relation you want to process incrementally.
  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.

## <a id="required-permissions" />Required permissions

The user who creates a streaming table is the streaming table owner and needs to 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 TABLE` privilege on the schema containing the streaming table.

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

* `USE CATALOG` privilege on the parent catalog and the `USE SCHEMA` privilege on the parent schema.
* Ownership of the streaming table, or both the `SELECT` and `MANAGE` privileges on the streaming table. `MANAGE` also lets the user manage privileges on, transfer ownership of, and drop the streaming table. See [MANAGE](https://docs.databricks.com/aws/en/data-governance/unity-catalog/access-control/privileges-reference.md#manage).
* The owner of the streaming table must have the `SELECT` privilege over the base tables referenced by the streaming table.

On serverless general compute, only the owner can refresh a streaming table. See [Permissions to create or refresh](https://docs.databricks.com/aws/en/sql/mv-st/compute.md#permissions).

For a user to be able to query the 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.

## Differences between streaming tables and other tables

Streaming tables are stateful tables, designed to handle each row only once as you process a growing dataset. Because most datasets grow continuously over time, streaming tables are good for most ingestion workloads. Streaming tables are optimal for pipelines that require data freshness and low latency. Streaming tables can also be useful for massive scale transformations, as results can be incrementally calculated as new data arrives, keeping results up to date without needing to fully recompute all source data with each update. Streaming tables are designed for data sources that are append-only.

Streaming tables accept additional commands such as `REFRESH`, which processes the latest data available in the sources provided in the query. Changes to the provided query only get reflected on new data by calling a `REFRESH`, not previously processed data. To apply the changes on existing data as well, you need to execute `REFRESH TABLE <table_name> FULL` to perform a `FULL REFRESH`. Full refreshes re-process all data available in the source with the latest definition. It is not recommended to call full refreshes on sources that don't keep the entire history of the data or have short retention periods, such as Kafka, as the full refresh truncates the existing data. You may not be able to recover old data if the data is no longer available in the source.

## Row filters and column masks

Row filters let you specify a function that applies as a filter whenever a table scan fetches rows. These filters ensure that subsequent queries only return rows for which the filter predicate evaluates to true.

Column masks let you mask a column's values whenever a table scan fetches rows. All future queries involving that column will receive the result of evaluating the function over the column, replacing the column's original value.

For more information on how to use row filters and column masks, see [Row filters and column masks](https://docs.databricks.com/aws/en/data-governance/unity-catalog/filters-and-masks/index.md).

### Managing Row Filters and Column Masks

Row filters and column masks on streaming tables should be added, updated, or dropped through the `CREATE OR REFRESH` statement.

### Behavior

* **Refresh as Definer**: When the `CREATE OR REFRESH` or `REFRESH` statements refresh a streaming table, row filter functions run with the definer's rights (as the table owner). This means the table refresh uses the security context of the user who created the streaming table.
* **Query**: While most filters run with the definer's rights, functions that check user context (such as `CURRENT_USER` and `IS_MEMBER`) are exceptions. These functions run as the invoker. This approach enforces user-specific data security and access controls based on the current user's context.

### Observability

Use `DESCRIBE EXTENDED`, `INFORMATION_SCHEMA`, or the Catalog Explorer to examine the existing row filters and column masks that apply to a given streaming table. This functionality allows users to audit and review data access and protection measures on streaming tables.

## <a id="st-limitations" />Limitations

* `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>` (you cannot use a streaming table as the source or target of a deep or shallow clone). See [Clone a table on Databricks](https://docs.databricks.com/aws/en/tables/operations/clone.md).
  * `COPY INTO`
  * `ANALYZE TABLE`
  * `RESTORE`
  * `TRUNCATE`
  * `GENERATE MANIFEST`
  * `[CREATE OR] REPLACE TABLE`
* When you share streaming tables with OpenSharing, additional limitations apply. See [Add streaming tables to a share](https://docs.databricks.com/aws/en/opensharing/create-share.md#streaming-tables).
* Renaming the table or changing the owner is not supported.
* Table constraints such as `PRIMARY KEY` and `FOREIGN KEY` are not supported for streaming tables in the `hive_metastore` catalog.

## Examples

```sql
-- Creates a streaming table that processes files stored in the given external location with
-- schema inference and evolution.
> CREATE OR REFRESH STREAMING TABLE raw_data
  AS SELECT * FROM STREAM read_files('abfss://container@storageAccount.dfs.core.windows.net/base/path');

-- Creates a streaming table that processes files with a known schema.
> CREATE OR REFRESH STREAMING TABLE csv_data (
    id int,
    ts timestamp,
    event string
  )
  AS SELECT *
  FROM STREAM read_files(
      's3://bucket/path',
      format => 'csv',
      schema => 'id int, ts timestamp, event string');

-- Creates a streaming table with an auto-incrementing identity column.
> CREATE OR REFRESH STREAMING TABLE customers_with_id (
    id BIGINT GENERATED ALWAYS AS IDENTITY,
    name string,
    region string
  )
  AS SELECT name, region FROM STREAM(customers_bronze);

-- Creates a streaming table with liquid clustering on order_date and customer_id.
> CREATE OR REFRESH STREAMING TABLE orders_with_cluster_by
  CLUSTER BY (order_date, customer_id)
  AS SELECT
    o_orderkey   AS order_id,
    o_custkey    AS customer_id,
    o_orderdate  AS order_date,
    o_totalprice AS total_price
  FROM STREAM(samples.tpch.orders);

-- Stores the data from Kafka in an append-only streaming table.
> CREATE OR REFRESH STREAMING TABLE firehose_raw
  COMMENT 'Stores the raw data from Kafka'
  TBLPROPERTIES ('delta.appendOnly' = 'true')
  AS SELECT
    value raw_data,
    offset,
    timestamp,
    timestampType
  FROM STREAM read_kafka(bootstrapServers => 'ips', subscribe => 'topic_name');

-- Creates a streaming table that scheduled to refresh when upstream data is updated.
-- The refresh frequency of triggered_data is at most once an hour.
> CREATE STREAMING TABLE triggered_data
  TRIGGER ON UPDATE AT MOST EVERY INTERVAL 1 hour
  AS SELECT *
  FROM STREAM source_stream_data;

-- Read data from another streaming table scheduled to run every hour.
> CREATE STREAMING TABLE firehose_bronze
  SCHEDULE EVERY 1 HOUR
  AS SELECT
    from_json(raw_data, 'schema_string') data,
    * EXCEPT (raw_data)
  FROM STREAM firehose_raw;

-- Creates a streaming table with schema evolution and data quality expectations.
-- The table creation or refresh fails if the data doesn't satisfy the expectation.
> CREATE OR REFRESH STREAMING TABLE avro_data (
    CONSTRAINT date_parsing EXPECT (to_date(dt) >= '2000-01-01') ON VIOLATION FAIL UPDATE
  )
  AS SELECT *
  FROM STREAM read_files('gs://my-bucket/avroData');

-- Creates a streaming table with a column constraint
> CREATE OR REFRESH STREAMING TABLE csv_data (
    id int PRIMARY KEY,
    ts timestamp,
    event string
  )
  AS SELECT *
  FROM STREAM read_files(
      's3://bucket/path',
      format => 'csv',
      schema => 'id int, ts timestamp, event string');

-- Creates a streaming table with a table constraint
> CREATE OR REFRESH STREAMING TABLE csv_data (
    id int,
    ts timestamp,
    event string,
    CONSTRAINT pk_id PRIMARY KEY (id)
  )
  AS SELECT *
  FROM STREAM read_files(
      's3://bucket/path',
      format => 'csv',
      schema => 'id int, ts timestamp, event string');

-- Creates a streaming table with a row filter and a column mask
> CREATE OR REFRESH STREAMING TABLE masked_csv_data (
    id int,
    name string,
    region string,
    ssn string MASK catalog.schema.ssn_mask_fn
  )
  WITH ROW FILTER catalog.schema.us_filter_fn ON (region)
  AS SELECT *
  FROM STREAM read_files('s3://bucket/path/sensitive_data')

-- Creates a streaming table using a FLOW to append data from files
> CREATE OR REFRESH STREAMING TABLE raw_data
  FLOW INSERT BY NAME SELECT * FROM STREAM read_files('abfss://my_path');

-- Creates a streaming table using an AUTO CDC flow to apply changes from a change feed
> CREATE OR REFRESH STREAMING TABLE target
  FLOW AUTO CDC
  FROM stream(cdc_data.users)
  KEYS (userId)
  SEQUENCE BY sequenceNum
  STORED AS SCD TYPE 1;

-- Creates a streaming table using a REPLACE USING flow to keep 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);
```

## Related articles

* [read\_files](https://docs.databricks.com/aws/en/sql/language-manual/functions/read_files.md)
* [read\_kafka](https://docs.databricks.com/aws/en/sql/language-manual/functions/read_kafka.md)
* [DROP TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-drop-table.md)
* [SHOW CREATE TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-aux-show-create-table.md)
* [constraint clause](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-table-constraint.md)
* [Filtering sensitive table data with row filters and column masks](https://docs.databricks.com/aws/en/data-governance/unity-catalog/filters-and-masks/index.md)
* [ALTER STREAMING TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-alter-streaming-table.md)
* [REFRESH TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-refresh-full.md)
* [AUTO CDC FLOW Clause](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-streaming-table-auto-cdc.md)
* [CREATE TABLE ... FLOW](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-table-flow.md)
* [The AUTO CDC APIs: Simplify change data capture with pipelines](https://docs.databricks.com/aws/en/ldp/cdc.md)
* [Load and process data incrementally with Lakeflow pipeline flows](https://docs.databricks.com/aws/en/ldp/concepts/flows.md)
