> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Data Definition (DDL)

<a id="sql-ddl" />

*Kinetica* supports the basic notion of SQL *tables* as containers of one or
more *columns* of data.

Table & column names must adhere to the supported
[naming criteria](/content/sql/naming#sql-naming-criteria).

A *column definition* consists of a *column type* and optional *column size*,
*column properties*, and nullability.  *Column properties* are used to optimize
data storage & speed.

The format of a defined *column* is *column name*, followed by
*column definition*.  A *column definition* is *column type* optionally followed
by any *column size* limit or *column properties* all enclosed in parentheses,
followed by an optional nullability statement:

```sql title="Column Definition Syntax" theme={null}
<column name> <column type> [(<column size / property list>)] [[NOT] NULL]
```

This format applies to any DDL statement requiring the definition of *columns*,
like [CREATE TABLE](/content/sql/ddl#sql-create-table) and [ALTER TABLE](/content/sql/ddl#sql-alter-table) (when
adding/modifying a column).

For example, the following are valid defined *columns*:

```sql Column Definition Examples theme={null}
id INTEGER(SHARD_KEY)            -- id is an integer and the table's shard key
name VARCHAR(64, TEXT_SEARCH)    -- name is a 64-byte limited string and text-searchable
ip IPV4                          -- ip is a string in IPv4 format
cost DECIMAL(10, 2)              -- cost is able to hold an 8.2 decimal
```

<a id="sql-column-types" />

## Column Types

### Number

| Data Type         | Description                                                                                                                                                                                                                                                                               |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `BOOLEAN`         | Effective *specific type*: [boolean](/content/concepts/types#types-chart)                                                                                                                                                                                                                 |
| `TINYINT`         | Effective *specific type*: [int8](/content/concepts/types#types-chart)                                                                                                                                                                                                                    |
| `BYTE`            | *Alias for* `TINYINT`                                                                                                                                                                                                                                                                     |
| `SMALLINT`        | Effective *specific type*: [int16](/content/concepts/types#types-chart)                                                                                                                                                                                                                   |
| `INTEGER`         | Effective *specific type*: [int](/content/concepts/types#types-chart)                                                                                                                                                                                                                     |
| `INT`             | *Alias for* `INTEGER`                                                                                                                                                                                                                                                                     |
| `BIGINT`          | Effective *specific type*: [long](/content/concepts/types#types-chart)                                                                                                                                                                                                                    |
| `DECIMAL`         | *Alias for* `BIGINT`                                                                                                                                                                                                                                                                      |
| `LONG`            | *Alias for* `BIGINT`                                                                                                                                                                                                                                                                      |
| `UNSIGNED BIGINT` | Effective *specific type*: [ulong](/content/concepts/types#types-chart)                                                                                                                                                                                                                   |
| `UNSIGNED LONG`   | *Alias for* `UNSIGNED BIGINT`                                                                                                                                                                                                                                                             |
| `REAL`            | Effective *specific type*: [float](/content/concepts/types#types-chart)                                                                                                                                                                                                                   |
| `FLOAT`           | *Alias for* `REAL`                                                                                                                                                                                                                                                                        |
| `DOUBLE`          | Effective *specific type*: [double](/content/concepts/types#types-chart)                                                                                                                                                                                                                  |
| `DECIMAL(P,S)`    | Effective *specific type*: [decimal(p,s)](/content/concepts/types#types-chart) <br /> <br /> Maximum precision `P` is *27* <br /> <br /> Maximum scale `S` is *18* <br /> <br /> Precision determines decimal storage size: <br /> <br /> *1* - *18*: *8* <br /> <br /> *19* - *27*: *12* |
| `NUMERIC`         | *Alias for* `DECIMAL(P,S)`                                                                                                                                                                                                                                                                |

### String

| Data Type    | Description                                                                                                                                                                                        |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `VARCHAR`    | Effective *specific type*: [string](/content/concepts/types#types-chart); character limit based on configured system property                                                                      |
| `VARCHAR(N)` | Effective *specific type*: the smallest [charN](/content/concepts/types#types-chart) type that is at least size `N`, or [string](/content/concepts/types#types-chart) if `N` is greater than *256* |
| `CHAR`       | *Alias for* `VARCHAR` / `VARCHAR(N)`                                                                                                                                                               |
| `STRING`     | *Alias for* `VARCHAR` / `VARCHAR(N)`                                                                                                                                                               |
| `TEXT`       | *Alias for* `VARCHAR` / `VARCHAR(N)`                                                                                                                                                               |
| `IPV4`       | *Shorthand for* `VARCHAR(IPV4)`, which applies the [IPV4](/content/sql/ddl#sql-column-properties) column property                                                                                  |
| `UUID`       | Effective *specific type* [uuid](/content/concepts/types#types-chart)                                                                                                                              |
| `JSON`       | Effective *specific type* [json](/content/concepts/types#types-chart)                                                                                                                              |

### Date/Time

| Data Type        | Description                                                                 |
| ---------------- | --------------------------------------------------------------------------- |
| `DATE`           | Effective *specific type*: [date](/content/concepts/types#types-chart)      |
| `DATETIME`       | Effective *specific type*: [datetime](/content/concepts/types#types-chart)  |
| `TIME`           | Effective *specific type*: [time](/content/concepts/types#types-chart)      |
| `TIMESTAMP`      | Effective *specific type*: [timestamp](/content/concepts/types#types-chart) |
| `TYPE_DATE`      | *Alias for* `DATE`                                                          |
| `TYPE_TIME`      | *Alias for* `TIME`                                                          |
| `TYPE_TIMESTAMP` | *Alias for* `TIMESTAMP`                                                     |

### Binary

| Data Type   | Description                                                             |
| ----------- | ----------------------------------------------------------------------- |
| `BLOB`      | Effective *specific type*: [bytes](/content/concepts/types#types-chart) |
| `BINARY`    | *Alias for* `BLOB`                                                      |
| `BYTES`     | *Alias for* `BLOB`                                                      |
| `VARBINARY` | *Alias for* `BLOB`                                                      |

### Geospatial

| Data Type        | Description                                                                                |
| ---------------- | ------------------------------------------------------------------------------------------ |
| `GEOMETRY`       | Effective *specific type*: [wkt](/content/concepts/types#types-chart) (*string* base type) |
| `ST_GEOMETRY`    | *Alias for* `GEOMETRY`                                                                     |
| `WKT`            | *Alias for* `GEOMETRY`                                                                     |
| `BLOB(WKT)`      | Effective *specific type*: [wkt](/content/concepts/types#types-chart) (*bytes* base type)  |
| `BINARY(WKT)`    | *Alias for* `BLOB(WKT)`                                                                    |
| `BYTES(WKT)`     | *Alias for* `BLOB(WKT)`                                                                    |
| `VARBINARY(WKT)` | *Alias for* `BLOB(WKT)`                                                                    |

### Composite

| Data Type            | Description                                                                                                                                                |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `BOOLEAN[N]`         | Effective *specific type*: [array(boolean)](/content/concepts/types#types-chart) (*string* base type)                                                      |
| `INTEGER[N]`         | Effective *specific type*: [array(int)](/content/concepts/types#types-chart) (*string* base type)                                                          |
| `BIGINT[N]`          | Effective *specific type*: [array(long)](/content/concepts/types#types-chart) (*string* base type)                                                         |
| `UNSIGNED BIGINT[N]` | Effective *specific type*: [array(ulong)](/content/concepts/types#types-chart) (*string* base type)                                                        |
| `VECTOR(N)`          | Effective *specific type*: [vector(n)](/content/concepts/types#types-chart) (*bytes* base type); generally used in [vector search](/content/vector_search) |
| `REAL[N]`            | Effective *specific type*: [array(float)](/content/concepts/types#types-chart) (*string* base type)                                                        |
| `DOUBLE[N]`          | Effective *specific type*: [array(double)](/content/concepts/types#types-chart) (*string* base type)                                                       |
| `VARCHAR[N]`         | Effective *specific type*: [array(string)](/content/concepts/types#types-chart) (*string* base type)                                                       |

<a id="sql-column-properties" />

## Column Properties

| Column Property   | Description                                                                                                                                                                                                                                                                                                                                          |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `COMPRESS(TYPE)`  | Applies [compress](/content/concepts/types#types-data-handling) data handling to a column using the specified compression type, enabling compression of its values; see [Column Compression](/content/concepts/column_compression) for details                                                                                                       |
| `DICT`            | Applies [dict](/content/concepts/types#types-data-handling) data handling to a column, enabling dictionary-encoding of its values; see [Dictionary Encoding](/content/concepts/dictionary_encoding) for details                                                                                                                                      |
| `INIT_WITH_NOW`   | For `DATE`, `TIME`, `DATETIME`, and `TIMESTAMP` column types, enables the database to use `NOW()` as the value when the column is not specified in an `INSERT` statement; also directs the database to replace empty strings (for `DATE`, `TIME`, & `DATETIME` columns) and invalid timestamps (for `TIMESTAMP` columns) with `NOW()` during inserts |
| `INIT_WITH_UUID`  | For `UUID` column type, enables the database to use a universally unique identifier (UUID) as the value when the column is not specified in an `INSERT` statement; also directs the database to replace empty strings (for `UUID` columns) with UUIDs                                                                                                |
| `IPV4`            | Treats the associated string-based column as an [IPv4 address](/content/concepts/types#types-data-types)                                                                                                                                                                                                                                             |
| `NORMALIZE`       | For `VECTOR` column type, automatically normalizes each vector to have a magnitude of *1*; see [Vector Type](/content/vector_search#vector-type)                                                                                                                                                                                                     |
| `PRIMARY_KEY`     | Treats the associated column as a [primary key](/content/concepts/tables#primary-key), or part of a *composite primary key* if other columns also have this property                                                                                                                                                                                 |
| `SHARD_KEY`       | Treats the associated column as a [shard key](/content/concepts/tables#shard-key), or part of a *composite* *shard key* if other columns also have this property                                                                                                                                                                                     |
| `TEXT_SEARCH`     | Applies [text-searchability](/content/concepts/types#types-data-handling) to a column                                                                                                                                                                                                                                                                |
| `UPDATE_WITH_NOW` | For `DATE`, `TIME`, `DATETIME`, and `TIMESTAMP` column types, enables the database to use `NOW()` as the value when the column is not specified in an `UPDATE` statement; also directs the database to replace empty strings (for `DATE`, `TIME`, & `DATETIME` columns) and invalid timestamps (for `TIMESTAMP` columns) with `NOW()` during updates |

<a id="sql-create-schema" />

## CREATE SCHEMA

[Schemas](/content/concepts/schemas) are logical containers for all
database objects (*tables*, *views*, etc.).  In order to place an object in a
*schema*, the *schema* must be created first--*schemas* will not be
automatically created when specified in `CREATE TABLE` or similar calls.

```sql title="CREATE SCHEMA Syntax" theme={null}
CREATE SCHEMA [IF NOT EXISTS] <schema name>
```

### Parameters

<AccordionGroup>
  <Accordion title="IF NOT EXISTS" id="if-not-exists" defaultOpen>
    Optional error suppression clause, which causes no error to be returned if a *schema* with the
    same name already exists
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>" defaultOpen>
    Name of the *schema* to create; must adhere to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria)
  </Accordion>
</AccordionGroup>

### Examples

```sql CREATE SCHEMA Example theme={null}
CREATE SCHEMA example_container
```

## ALTER SCHEMA

Alters the configuration of a [schema](/content/sql/ddl#sql-create-schema).  The
name of a *schema* is the only property that can be altered.

<a id="sql-alter-schema-rename" />

### Rename Schema

A [schema](/content/sql/ddl#sql-create-schema) can be renamed.

```sql title="Rename Schema Syntax" theme={null}
ALTER SCHEMA <schema name>
RENAME TO <new schema name>
```

```sql Rename Schema Example theme={null}
ALTER SCHEMA example_container
RENAME TO example_container_renamed
```

## DROP SCHEMA

Removes an existing [schema](/content/sql/ddl#sql-create-schema).

```sql title="DROP SCHEMA Syntax" theme={null}
DROP SCHEMA [IF EXISTS] <schema name> [CASCADE]
```

### Parameters

<AccordionGroup>
  <Accordion title="IF EXISTS" id="if-exists" defaultOpen>
    Optional error-suppression clause; if specified, no error will be returned if the given
    *schema* does not exist
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-2" defaultOpen>
    Name of the *schema* to remove
  </Accordion>

  <Accordion title="CASCADE" id="cascade" defaultOpen>
    Drops all objects contained within the schema; if not specified, an error will be returned if the
    given *schema* contains any *tables*, *views*, etc.
  </Accordion>
</AccordionGroup>

### Examples

To drop a *schema*, including all contained objects:

```sql DROP SCHEMA Example theme={null}
DROP SCHEMA example_container CASCADE
```

## SHOW SCHEMA

Outputs the DDL statement required to reconstruct the given *schema*.

```sql title="SHOW SCHEMA Syntax" theme={null}
SHOW [CREATE] SCHEMA < <schema name> | * >
```

<Info>
  The response to `SHOW SCHEMA` is a single-column result set
  with the DDL statement as the value in the `DDL` column, shown below with
  the column separators returned by <Badge color="blue-destructive">kisql</Badge>.
</Info>

### Parameters

<AccordionGroup>
  <Accordion title="CREATE" id="create" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="SCHEMA" id="schema" defaultOpen>
    Optional clause to avoid ambiguity; if omitted, and a *table* or *view* exists with the given
    name, the command will be interpreted as a `SHOW TABLE` statement instead
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-3" defaultOpen>
    Name of the *schema* whose contained *tables'* & *views'* DDL will be output; use `*` instead
    to output the DDL of all *schemas*, *tables*, & *views*
  </Accordion>
</AccordionGroup>

### Examples

To output the DDL for the example schema created in the
[CREATE SCHEMA](/content/sql/ddl#sql-create-schema) section:

```sql SHOW SCHEMA Example theme={null}
SHOW CREATE SCHEMA example_container
```

```sql SHOW SCHEMA Output theme={null}
| CREATE SCHEMA "example_container";   |
```

## DESCRIBE SCHEMA

Lists the contained *tables* and *views* of a given *schema*.

```sql title="DESCRIBE SCHEMA Syntax" theme={null}
DESC[RIBE] [SCHEMA] <schema name>
```

### Parameters

<AccordionGroup>
  <Accordion title="SCHEMA" id="schema-2" defaultOpen>
    Optional clause to avoid ambiguity; if omitted, and a *table* or *view* exists with the given
    name, the command will be interpreted as a `DESCRIBE TABLE` statement instead
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-4" defaultOpen>
    Name of the *schema* whose contained *tables* & *views* will be listed
  </Accordion>
</AccordionGroup>

### Examples

To describe the tables contained in the `demo` schema, into
which demo data is usually downloaded:

```sql DESCRIBE SCHEMA Example theme={null}
DESC demo
```

```sql DESCRIBE SCHEMA Output theme={null}
+------------+
| Set_name   |
+------------+
| stocks     |
| nyctaxi    |
| flights    |
+------------+
```

<a id="sql-current-schema" />

## SET CURRENT SCHEMA

To override the [default schema](/content/concepts/schemas#schema-default) with a different
*schema*, the following syntax can be used:

<Info>
  This command is only available through
  [KiSQL](/content/tools/kisql) or database clients configured with
  the [Kinetica ODBC/JDBC driver](/content/connectors/sql_guide#odbc-jdbc).
</Info>

```sql title="SET CURRENT SCHEMA Syntax" theme={null}
SET CURRENT SCHEMA [<schema name>]
```

Omitting `schema name` will switch back to the original *default schema*.

<a id="sql-create-table" />

## CREATE TABLE

Creates a new [table](/content/concepts/tables).

```sql title="CREATE TABLE Syntax" theme={null}
CREATE [OR REPLACE] [REPLICATED] [TEMP] TABLE [IF NOT EXISTS] [<schema name>.]<table name>
(
    <column name> <column definition> [COMMENT '<column comment>'],
    ...
    <column name> <column definition> [COMMENT '<column comment>'],
    [[SOFT] PRIMARY KEY (<column list>)],
    [SHARD KEY (<column list>)],
    [FOREIGN KEY
        (<column list>) REFERENCES <foreign table name>(<foreign column list>) [AS <foreign key name>],
        ...
        (<column list>) REFERENCES <foreign table name>(<foreign column list>) [AS <foreign key name>]
    ]
)
[<partition clause>]
[<tier strategy clause>]
[<index clause>]
[<table property clause>]
```

### Parameters

<AccordionGroup>
  <Accordion title="OR REPLACE" id="or-replace" defaultOpen>
    Any existing *table* or *view* with the same name will be dropped before creating this one;
    mutually exclusive with `IF NOT EXISTS`
  </Accordion>

  <Accordion title="REPLICATED" id="replicated" defaultOpen>
    The *table* will be distributed within the database as a [replicated](/content/concepts/tables#replicated)
    *table*
  </Accordion>

  <Accordion title="TEMP" id="temp" defaultOpen>
    The *table* will be a [memory-only table](/content/concepts/tables_memory_only); which, among
    other things, means it will not be persisted (if the database is restarted, the *table* will be
    removed), but it will have increased ingest performance
  </Accordion>

  <Accordion title="IF NOT EXISTS" id="if-not-exists-2" defaultOpen>
    If a *table* or *view* with the same name exists, do nothing; mutually exclusive with
    `OR REPLACE`
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-5" defaultOpen>
    Name of the *schema* that will contain the created *table*; if no *schema* is specified, the
    *table* will be created in the user's [default schema](/content/concepts/schemas#schema-default)
  </Accordion>

  <Accordion title="<table name>" id="<table-name>" defaultOpen>
    Name of the *table* to create; must adhere to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria)
  </Accordion>

  <Accordion title="<column name>" id="<column-name>" defaultOpen>
    Name of a *column* to create within the *table*; must adhere to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria)
  </Accordion>

  <Accordion title="<column definition>" id="<column-definition>" defaultOpen>
    Definition of the column associated with `<column name>`; see [Data Definition (DDL)](/content/sql/ddl#sql-ddl) for column
    format
  </Accordion>

  <Accordion title="COMMENT '<column comment>'" id="comment-<column-comment>" defaultOpen>
    Apply column comment `<column comment>` to the column associated with `<column name>`
  </Accordion>

  <Accordion title="SOFT" id="soft" defaultOpen>
    Modifier for `PRIMARY KEY` that creates a [soft primary key](/content/concepts/tables#soft-primary-key) instead
    of a standard [primary key](/content/concepts/tables#primary-key)
  </Accordion>

  <Accordion title="PRIMARY KEY (<column list>)" id="primary-key-<column-list>" defaultOpen>
    Optional [primary key](/content/concepts/tables#primary-key) specification clause, where `<column list>` is a
    comma-separated list of columns to use as the *primary key* for the *table*
  </Accordion>

  <Accordion title="SHARD KEY (<column list>)" id="shard-key-<column-list>" defaultOpen>
    Optional [shard key](/content/concepts/tables#shard-key) specification clause, where `<column list>` is a
    comma-separated list of columns to use as the *shard key* for the *table*
  </Accordion>

  <Accordion title="FOREIGN KEY ..." id="foreign-key" defaultOpen>
    Optional comma-separated set of [foreign key](/content/concepts/tables#foreign-key) specification clauses, with
    the following parameters:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Parameter</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>\<column list></code></td>
            <td>Comma-separated list of columns in the *table* to create that will reference a matching set of *primary key* columns in another *table*</td>
          </tr>

          <tr>
            <td><code>\<foreign table name></code></td>
            <td>Name of target *table* referred to in this *foreign key*</td>
          </tr>

          <tr>
            <td><code>\<foreign column list></code></td>
            <td>The *primary key* columns in the target *table* referred to in this *foreign key*, matching the list of columns specified in <code>\<column list></code> in the table to create</td>
          </tr>

          <tr>
            <td><code>AS \<foreign key name></code></td>
            <td>Optional alias for the *foreign key*</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="<partition clause>" id="<partition-clause>" defaultOpen>
    Defines a [partitioning](/content/concepts/tables#partitioning) scheme for the *table* to create
  </Accordion>

  <Accordion title="<tier strategy clause>" id="<tier-strategy-clause>" defaultOpen>
    Defines the [tier strategy](/content/rm/concepts#rm-concepts-tier-strategy) for the *table* to create
  </Accordion>

  <Accordion title="<index clause>" id="<index-clause>" defaultOpen>
    Applies any number of [column indexes](/content/concepts/indexes#column-index),
    [chunk skip indexes](/content/concepts/indexes#chunk-skip-index),
    [geospatial indexes](/content/concepts/indexes#geospatial-index),
    [CAGRA indexes](/content/concepts/indexes#cagra-index), or
    [HNSW indexes](/content/concepts/indexes#hnsw-index)
    to the *table* to create
  </Accordion>

  <Accordion title="<table property clause>" id="<table-property-clause>" defaultOpen>
    Assigns table properties, from a subset of those available, to the *table* to create
  </Accordion>
</AccordionGroup>

### Examples

To create a table with various column types and properties:

```sql CREATE TABLE Example theme={null}
CREATE TABLE example.various_types
(
    i    INTEGER NOT NULL                                 COMMENT 'non-nullable integer, part of primary key (defined at end)',
    bi   BIGINT NOT NULL                                  COMMENT 'long, part of primary key, shard key, foreign key source (defined at end)',
    b    BOOLEAN                                          COMMENT '0s and 1s only',
    ub   UNSIGNED BIGINT                                  COMMENT 'native unsigned long',
    r    REAL                                             COMMENT 'native float',
    d    DOUBLE                                           COMMENT 'native double',
    s    VARCHAR(TEXT_SEARCH)                             COMMENT 'string, searchable, only limited in size by system-configured value',
    c    VARCHAR(30, DICT)                                COMMENT 'char32 using dictionary-encoding of values',
    p    VARCHAR(256, TEXT_SEARCH)                        COMMENT 'char256, searchable',
    ip   IPV4                                             COMMENT 'IP address',
    ui   UUID(INIT_WITH_UUID)                             COMMENT 'UUID',
    ts   TIMESTAMP                                        COMMENT 'timestamp',
    td   DATE                                             COMMENT 'simple date',
    tt   TIME                                             COMMENT 'simple time',
    dt   DATETIME(INIT_WITH_NOW)                          COMMENT 'date/time',
    dc   DECIMAL                                          COMMENT 'integer of up to 27 digits',
    dc8  DECIMAL(18, 4)                                   COMMENT '8-byte decimal',
    dc12 DECIMAL(27, 18)                                  COMMENT '12-byte decimal',
    n    NUMERIC(18, 4)                                   COMMENT 'alias for DECIMAL(18, 4)',
    byt  BYTES                                            COMMENT 'BLOB',
    w    WKT                                              COMMENT 'geospatial column for WKT string data',
    j    JSON                                             COMMENT 'JSON string',
    v    VECTOR(10)                                       COMMENT 'vector column holding 10 floating point values',
    ai   INTEGER[3]                                       COMMENT 'array column holding 3 integer values',
    PRIMARY KEY (i, bi),                                  /* primary key columns must be NOT NULL                                               */
    SHARD KEY (bi),                                       /* shard key columns must be part of the primary key                                  */
    FOREIGN KEY (bi) REFERENCES example.lookup(id) AS fk  /* foreign key is often on the shard key                                              */
)
INDEX (ip)                                                /* index on IP column                                                                 */
INDEX (ts)                                                /* index on timestamp column                                                          */
```

<a id="sql-create-table-partition" />

### Partition Clause

A *table* can be further segmented into *partitions*.  The supported *partition*
types are:

<CardGroup cols={3}>
  <Card title="Range" href="/content/sql/ddl#sql-create-table-partition-by-range">
    Partition by defined value ranges to improve filter & join performance
  </Card>

  <Card title="Interval" href="/content/sql/ddl#sql-create-table-partition-by-interval">
    Partition by numeric or time-based intervals with dynamic partition creation
  </Card>

  <Card title="List" href="/content/sql/ddl#sql-create-table-partition-by-list">
    Partition by discrete sets of values to improve filter performance
  </Card>

  <Card title="Hash" href="/content/sql/ddl#sql-create-table-partition-by-hash">
    Partition by hash of key columns to improve equi-join performance
  </Card>

  <Card title="Series" href="/content/sql/ddl#sql-create-table-partition-by-series">
    Partition into a sequence of dynamically-allocated partitions, filling each to a threshold
  </Card>
</CardGroup>

See [Partitioning](/content/concepts/tables#partitioning) for details.

<a id="sql-create-table-partition-by-range" />

#### Range Partitioning

The general format for the [range partition](/content/concepts/tables#partitioning-by-range) clause
is:

```sql title="PARTITION BY RANGE Syntax" theme={null}
PARTITION BY RANGE ( <column expression> )
[
    PARTITIONS
    (
        <partition name> [ MIN ( <least value> ) ] [ MAX ( <greatest value> ) ],
        ...
        <partition name> [ MIN ( <least value> ) ] [ MAX ( <greatest value> ) ]
    )
]
```

The partition definition clause, `PARTITIONS`, is optional, though it is
recommended to define partitions at table creation time, when feasible.

<Warning>
  Defining (adding) partitions after data has been loaded will
  result in a performance penalty as the database moves existing records
  targeted for the new partition from the *default partition* into it.
</Warning>

For example, to create a *range-partitioned* *table* with the following
criteria:

* partitioned on the date/time of the order

* partitions for years:

  * *2014* - *2016*
  * *2017*
  * *2018*
  * *2019*

* records not in that range go to the *default partition*

```sql PARTITION BY RANGE Example theme={null}
CREATE TABLE example.customer_order_range_partition_by_year
(
    id           INT NOT NULL,
    customer_id  INT NOT NULL,
    total_price  DECIMAL(10,2),
    purchase_ts  TIMESTAMP NOT NULL
)
PARTITION BY RANGE (YEAR(purchase_ts))
PARTITIONS
(
    order_2014_2016 MIN(2014) MAX(2017),
    order_2017                MAX(2018),
    order_2018                MAX(2019),
    order_2019                MAX(2020)
)
```

<a id="sql-create-table-partition-by-interval" />

#### Interval Partitioning

The general format for the [interval partition](/content/concepts/tables#partitioning-by-interval)
clause is:

```sql title="PARTITION BY INTERVAL Syntax" theme={null}
PARTITION BY INTERVAL ( <column expression> )
PARTITIONS
(
    STARTING [AT] (<least value>) INTERVAL (<interval size>)
)
```

For example, to create an *interval-partitioned* *table* with the following
criteria:

* partitioned on the date/time of the order
* one partition for each year from *2014* on
* later year partitions are added as necessary
* records prior to *2014* go to the *default partition*

```sql PARTITION BY INTERVAL (Year) Syntax theme={null}
CREATE TABLE example.customer_order_interval_partition_by_year
(
    id           INT NOT NULL,
    customer_id  INT NOT NULL,
    total_price  DECIMAL(10,2),
    purchase_ts  TIMESTAMP
)
PARTITION BY INTERVAL (YEAR(purchase_ts))
PARTITIONS
(
    STARTING AT (2014) INTERVAL (1)
)
```

To create an *interval-partitioned* *table* with the following criteria:

* partitioned on the date/time of the order
* one partition for each day from *January 1st, 2014* on
* later day partitions are added as necessary
* records prior to *2014* go to the *default partition*

```sql PARTITION BY INTERVAL (Day) Syntax theme={null}
CREATE TABLE example.customer_order_interval_partition_by_day_timestampdiff
(
    id           INT NOT NULL,
    customer_id  INT NOT NULL,
    total_price  DECIMAL(10,2),
    purchase_ts  TIMESTAMP
)
PARTITION BY INTERVAL (TIMESTAMPDIFF(DAY, '2014-01-01', purchase_ts))
PARTITIONS
(
    STARTING AT (0) INTERVAL (1)
)
```

The same *interval-partitioned* scheme above can be created using the timestamp
column directly, with the help of the `INTERVAL` function
*(described in the* [Date/Time Functions](/content/sql/query#sql-datetime-functions) *section)*:

```sql PARTITION BY INTERVAL (Day) Alternate Syntax theme={null}
CREATE TABLE example.customer_order_interval_partition_by_day_interval
(
    id           INT NOT NULL,
    customer_id  INT NOT NULL,
    total_price  DECIMAL(10,2),
    purchase_ts  TIMESTAMP
)
PARTITION BY INTERVAL (purchase_ts)
PARTITIONS
(
    STARTING AT ('2014-01-01') INTERVAL (INTERVAL '1' DAY)
)
```

This scheme can be easily modified to create an hourly partition instead:

```sql PARTITION BY INTERVAL (Hour) Syntax theme={null}
CREATE TABLE example.customer_order_interval_partition_by_hour_interval
(
    id           INT NOT NULL,
    customer_id  INT NOT NULL,
    total_price  DECIMAL(10,2),
    purchase_ts  TIMESTAMP
)
PARTITION BY INTERVAL (purchase_ts)
PARTITIONS
(
    STARTING AT ('2014-01-01') INTERVAL (INTERVAL '1' HOUR)
)
```

<a id="sql-create-table-partition-by-list" />

#### List Partitioning

The [list partition](/content/concepts/tables#partitioning-by-list) clause has two forms:

<CardGroup cols={2}>
  <Card title="manual" href="/content/sql/ddl#sql-create-table-partition-by-list-manual">
    Define partitions as specific value lists; unmatched records go to the default partition
  </Card>

  <Card title="automatic" href="/content/sql/ddl#sql-create-table-partition-by-list-automatic">
    Database automatically creates a partition for each distinct partition key value
  </Card>
</CardGroup>

<a id="sql-create-table-partition-by-list-manual" />

<p><strong>Manual</strong></p>

The general format for the
[manual list partition](/content/concepts/tables#partitioning-by-list-manual) clause is:

```sql title="PARTITION BY LIST Syntax" theme={null}
PARTITION BY LIST ( <column expression list> )
[
    PARTITIONS
    (
        <partition name> VALUES ( <value lists> ),
        ...
        <partition name> VALUES ( <value lists> )
    )
]
```

The partition definition clause, `PARTITIONS`, is optional, though it is
recommended to define partitions at table creation time, when feasible.

<Warning>
  Defining (adding) partitions after data has been loaded will
  result in a performance penalty as the database moves existing records
  targeted for the new partition from the *default partition* into it.
</Warning>

For example, to create a *manual list-partitioned* *table* with the following
criteria:

* partitioned on the date/time of the order

* partitions for years:

  * *2014* - *2016*
  * *2017*
  * *2018*
  * *2019*

* records not in that list go to the *default partition*

```sql PARTITION BY LIST (Year) Example theme={null}
CREATE TABLE example.customer_order_manual_list_partition_by_year
(
    id           INT NOT NULL,
    customer_id  INT NOT NULL,
    total_price  DECIMAL(10,2),
    purchase_ts  TIMESTAMP NOT NULL
)
PARTITION BY LIST (YEAR(purchase_ts))
PARTITIONS
(
    order_2014_2016 VALUES (2014, 2015, 2016),
    order_2017      VALUES (2017),
    order_2018      VALUES (2018),
    order_2019      VALUES (2019)
)
```

To create a *manual list-partitioned* *table* with a multi-column key and the
following criteria:

* partitioned on the date/time of the order

* each partition corresponds to a unique year & month pair

* partitions for years/months:

  * *February 2016* & *March 2016*
  * *March 2020*

* records not in that list go to the *default partition*

```sql PARTITION BY LIST (Month) Example theme={null}
CREATE TABLE example.customer_order_manual_list_partition_by_year_and_month
(
    id           INT NOT NULL,
    customer_id  INT NOT NULL,
    total_price  DECIMAL(10,2),
    purchase_ts  TIMESTAMP NOT NULL
)
PARTITION BY LIST (YEAR(purchase_ts), MONTH(purchase_ts))
PARTITIONS
(
    order_2016_0203 VALUES ((2016, 2), (2016, 3)),
    order_2020_03   VALUES ((2020, 3))
)
```

<a id="sql-create-table-partition-by-list-automatic" />

<p><strong>Automatic</strong></p>

The general format for the
[automatic list partition](/content/concepts/tables#partitioning-by-list-automatic) clause is:

```sql title="Automatic PARTITION BY LIST Syntax" theme={null}
PARTITION BY LIST ( <column expression list> )
AUTOMATIC
```

To create an *automatic list-partitioned* *table* with the following criteria:

* partitioned on the date/time of the order
* one partition for each unique year & month across all orders
* partitions are added as necessary

```sql Automatic PARTITION BY LIST (Month) Example theme={null}
CREATE TABLE example.customer_order_automatic_list_partition_by_year_and_month
(
    id           INT NOT NULL,
    customer_id  INT NOT NULL,
    total_price  DECIMAL(10,2),
    purchase_ts  TIMESTAMP NOT NULL
)
PARTITION BY LIST (YEAR(purchase_ts), MONTH(purchase_ts))
AUTOMATIC
```

<a id="sql-create-table-partition-by-hash" />

#### Hash Partitioning

The general format for the
[hash partition](/content/concepts/tables#partitioning-by-hash) clause is:

```sql title="PARTITION BY HASH Syntax" theme={null}
PARTITION BY HASH ( <column expressions> )
PARTITIONS <total partitions>
```

To create a *hash-partitioned* *table* with the following criteria:

* partitioned on the date/time of the order
* distributed among the fixed set of partitions, based on the hash of the year &
  month of the order
* 10 partitions

```sql PARTITION BY HASH Example theme={null}
CREATE TABLE example.customer_order_hash_partition_by_year_and_month
(
    id           INT NOT NULL,
    customer_id  INT NOT NULL,
    total_price  DECIMAL(10,2),
    purchase_ts  TIMESTAMP NOT NULL
)
PARTITION BY HASH (YEAR(purchase_ts), MONTH(purchase_ts))
PARTITIONS 10
```

<a id="sql-create-table-partition-by-series" />

#### Series Partitioning

The general format for the
[series partition](/content/concepts/tables#partitioning-by-series) clause is:

```sql title="PARTITION BY SERIES" theme={null}
PARTITION BY SERIES ( <column list> )
[PERCENT_FULL <percentage>]
```

The `PERCENT_FULL` should be an integer between *1* and *100*; the default is
*50%*.

To create a *series-partitioned* *table* with the following criteria:

* partitioned on the customer of each order
* partitions with *closed* key sets will contain all orders from a set of unique
  customers
* *50%* fill threshold

```sql PARTITION BY SERIES Example theme={null}
CREATE TABLE example.customer_order_series_partition_error_default_percent_full
(
    id           INT NOT NULL,
    customer_id  INT NOT NULL,
    total_price  DECIMAL(10,4),
    purchase_ts  TIMESTAMP NOT NULL
    SHARD KEY(customer_id)
)
PARTITION BY SERIES (customer_id)
```

To create a *series-partitioned* *track table* with the following criteria:

* partitioned on the *track ID*
* partitions with *closed* key sets will contain all points from a unique set of
  tracks
* *25%* fill threshold

```sql PARTITION BY SERIES (Tracks) Example theme={null}
CREATE TABLE example.route_series_partition_by_track
(
    TRACKID    VARCHAR NOT NULL,
    x          DOUBLE NOT NULL,
    y          DOUBLE NOT NULL,
    TIMESTAMP  TIMESTAMP NOT NULL
)
PARTITION BY SERIES (TRACKID)
PERCENT_FULL 25
```

<a id="sql-create-table-tier-strategy" />

### Tier Strategy Clause

A *table* can have a [tier strategy](/content/rm/concepts#rm-concepts-tier-strategy) specified
at creation time.  If not assigned a *tier strategy* upon creation, a
[default tier strategy](/content/rm/configuration#rm-config-tier-strategy-default)
will be assigned.

```sql title="TIER STRATEGY Clause Syntax" theme={null}
TIER STRATEGY
(
    <tier strategy>,
    ...
    <tier strategy>
)
```

For example, to create a `customer_order` *table* with an above-average
[eviction priority](/content/rm/concepts#rm-concepts-eviction-priority) in the
[RAM Tier](/content/rm/concepts#rm-concepts-tiers-ram):

```sql TIER STRATEGY Example theme={null}
CREATE OR REPLACE TABLE example.customer_order
(
    id          INT NOT NULL,
    customer_id INT NOT NULL,
    total_price DECIMAL(10,2),
    purchase_ts TIMESTAMP,
    SHARD KEY (customer_id)
)
TIER STRATEGY
(
    ( ( VRAM 1, RAM 7, PERSIST 5 ) )
)
```

If not specified, the *default tier strategy* will be assigned:

```sql Default TIER STRATEGY Example theme={null}
CREATE OR REPLACE TABLE example.customer_order
(
    id          INT NOT NULL,
    customer_id INT NOT NULL,
    total_price DECIMAL(10,2),
    purchase_ts TIMESTAMP,
    SHARD KEY (customer_id)
)
```

```sql SHOW TABLE Command to Display TIER STRATEGY theme={null}
SHOW CREATE TABLE example.customer_order
```

```sql SHOW TABLE Command Output theme={null}
| CREATE TABLE "example"."customer_order"
(
    "id" INTEGER NOT NULL,
    "customer_id" INTEGER (shard_key) NOT NULL,
    "total_price" DECIMAL (10, 2),
    "purchase_ts" TIMESTAMP
)
TIER STRATEGY (
    ( ( VRAM 1, RAM 7, PERSIST 5 ) )
); |
```

<Info>
  The response to `SHOW TABLE` is a single-record result set
  with the DDL statement as the value in the `DDL` column, shown here with
  the column separators returned by <Badge color="blue-destructive">kisql</Badge>.
</Info>

<a id="sql-create-table-index" />

### Index Clause

A *table* can have any number of [indexes](/content/concepts/indexes)
applied to any of its columns at creation time.

The types of explicit indexes supported are:

<CardGroup cols={3}>
  <Card title="Column (Attribute) Index" href="/content/concepts/indexes#column-index">
    B-tree index on a column for equality and range filter performance
  </Card>

  <Card title="Low Cardinality Index" href="/content/concepts/indexes#low-cardinality-index">
    Column index optimized for columns with many duplicate values, using less memory
  </Card>

  <Card title="Chunk Skip Index" href="/content/concepts/indexes#chunk-skip-index">
    Improves equality-based filtering, especially on partition key columns
  </Card>

  <Card title="Geospatial Index" href="/content/concepts/indexes#geospatial-index">
    Improves performance of geospatial functions on geometry columns
  </Card>

  <Card title="CAGRA Index" href="/content/concepts/indexes#cagra-index">
    GPU-accelerated graph-based index for vector similarity search; requires manual refresh
  </Card>

  <Card title="HNSW Index" href="/content/concepts/indexes#hnsw-index">
    Graph-based index for vector similarity search; automatically maintained
  </Card>
</CardGroup>

```sql title="Index Clause Syntax" theme={null}
<[ATTRIBUTE] | CHUNK [SKIP] | LOW CARDINALITY | GEOSPATIAL | CAGRA | HNSW> INDEX (<column>)
...
<[ATTRIBUTE] | CHUNK [SKIP] | LOW CARDINALITY | GEOSPATIAL | CAGRA | HNSW> INDEX (<column>)
```

For example, to create a *table* with the following indexes:

* *column index* on `last_name`
* *low-cardinality index* on `dept_id`
* *chunk skip index* on `id`
* *geospatial index* on `work_district`
* *geospatial index* on the pair of `office_longitude` & `office_latitude`
* *CAGRA index* on `profile`

```sql Index Example theme={null}
CREATE TABLE example.employee
(
    id INTEGER NOT NULL,
    dept_id INTEGER NOT NULL,
    manager_id INTEGER,
    first_name VARCHAR(30),
    last_name VARCHAR(30),
    sal DECIMAL(18,4),
    hire_date DATE,
    work_district WKT,
    office_longitude REAL,
    office_latitude REAL,
    profile VECTOR(10),
    PRIMARY KEY (id, dept_id),
    SHARD KEY (dept_id)
)
INDEX (last_name)
LOW CARDINALITY INDEX (dept_id)
CHUNK SKIP INDEX (id)
GEOSPATIAL INDEX (work_district)
GEOSPATIAL INDEX (office_longitude, office_latitude)
CAGRA INDEX (profile)
HNSW INDEX (profile)
```

<a id="sql-create-table-prop" />

### Table Property Clause

A subset of *table* properties can be applied to the *table* at creation time.

```sql title="Table Property Clause" theme={null}
USING TABLE PROPERTIES
(
    <table property> = <value>,
    ...
    <table property> = <value>
)
```

Available table properties include:

<AccordionGroup>
  <Accordion title="CHUNK COLUMN MEMORY" id="chunk-column-memory" defaultOpen>
    Size of the blocks of memory holding the data, when loaded; specified as the
    maximum number of bytes any one column should hold.

    <Info>
      The size of dictionary-encoded columns is estimated.
    </Info>
  </Accordion>

  <Accordion title="CHUNK MEMORY" id="chunk-memory" defaultOpen>
    Size of the blocks of memory holding the data, when loaded; specified as the
    maximum total number of bytes all columns should hold.

    <Info>
      The size of dictionary-encoded columns is estimated.
    </Info>
  </Accordion>

  <Accordion title="CHUNK SIZE" id="chunk-size" defaultOpen>
    Size of the blocks of memory holding the data, when loaded; specified as the
    maximum number of records each block of memory should hold.
  </Accordion>

  <Accordion title="COMPRESSION_CODEC" id="compression_codec" defaultOpen>
    The default [compression](/content/concepts/column_compression) type to apply
    to columns of this table not explicitly given one.
  </Accordion>

  <Accordion title="NO_ERROR_IF_EXISTS" id="no_error_if_exists" defaultOpen>
    Error suppression option, which causes no error to be returned if a *table*
    with the same name already exists; default is `FALSE`.

    <Info>
      This is the same option as `IF NOT EXISTS`.
    </Info>
  </Accordion>

  <Accordion title="PRIMARY_KEY_TYPE" id="primary_key_type" defaultOpen>
    The type of [primary key index](/content/concepts/indexes#primary-key-index) to use.

    The default is `memory`.

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Type</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>memory</code></td>
            <td>*Primary key index* is loaded into memory, occupying RAM but improving performance.</td>
          </tr>

          <tr>
            <td><code>disk</code></td>
            <td>*Primary key index* is stored on disk only, increasing available RAM at the cost of some performance.</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="TTL" id="ttl" defaultOpen>
    The [time-to-live (TTL)](/content/concepts/ttl) for the *table*; if not set,
    the *table* will not expire.
  </Accordion>
</AccordionGroup>

For example, to create a table with up to *1,000,000* records per chunk and that
will expire in *15* minutes:

```sql Table Property Example theme={null}
CREATE OR REPLACE TABLE example.customer_order
(
    id          INTEGER NOT NULL,
    customer_id INTEGER NOT NULL,
    total_price DECIMAL(10,2),
    purchase_ts TIMESTAMP,
    SHARD KEY (customer_id)
)
USING TABLE PROPERTIES (CHUNK SIZE = 1000000, TTL = 15)
```

<a id="sql-create-ext-table" />

## CREATE EXTERNAL TABLE

Creates a new [external table](/content/concepts/external_tables), which is
a database object whose source data is located in one or more files, either
internal or external to the database.

```sql title="CREATE EXTERNAL TABLE Syntax" theme={null}
CREATE [OR REPLACE] [REPLICATED] [TEMP] [LOGICAL | MATERIALIZED] EXTERNAL TABLE [<schema name>.]<table name>
[<table definition clause>]
<
	REMOTE QUERY '<source data query>'
	|
	FILE PATHS <file paths>
		[FORMAT <[DELIMITED] TEXT [(<delimited text options>)] | AVRO | JSON | PARQUET | SHAPEFILE>]
>
[WITH OPTIONS (<load option name> = '<load option value>'[,...])]
[<partition clause>]
[<tier strategy clause>]
[<index clause>]
[<table property clause>]
```

<Info>
  For contextualized examples, see [Examples](/content/sql/ddl#sql-create-ext-table-examples).
  For copy/paste examples, see [Loading Data](/content/snippets/load-data).  For an overview
  of loading data into *Kinetica*, see [Data Loading Concepts](/content/load_data/concepts).
</Info>

The source data can be located in either of the following locations:

* in [KiFS](/content/tools/kifs)
* on a remote system, accessible via a
  [data source](/content/sql/ddl#sql-create-data-source)

A materialized *external table* (default) that uses a *data source* can perform
a one-time load upon creation and optionally subscribe for updates on an
interval, depending on the *data source* provider:

| Provider | Description                                                                                                                                 | One-Time Load | Subscription |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ------------ |
| *Azure*  | Microsoft blob storage                                                                                                                      | Yes           | Yes          |
| *GCS*    | Google Cloud Storage                                                                                                                        | Yes           | Yes          |
| *HDFS*   | Apache Hadoop Distributed File System                                                                                                       | Yes           |              |
| *JDBC*   | Java DataBase Connectivity; using a user-supplied driver or one of the drivers on the list [supported list](/content/concepts/jdbc_drivers) | Yes           | Yes          |
| *S3*     | Amazon S3 Bucket                                                                                                                            | Yes           | Yes          |

See [Manage Subscription](/content/sql/ddl#sql-alter-table-manage-sub) for pausing, resuming, canceling,
and dropping subscriptions on the *external table*.

Although an *external table* cannot use a *data source* configured for *Kafka*,
a standard *table* can have *Kafka* data streamed into it via a
[LOAD INTO](/content/sql/load#sql-load-file-server) command that references such a
*data source*.

The use of *external tables* with [ring resiliency](/content/ha)
has additional [considerations](/content/ha/ha_configuration#ring-extdata).

### Parameters

<AccordionGroup>
  <Accordion title="OR REPLACE" id="or-replace-2" defaultOpen>
    Any existing *table* or *view* with the same name will be dropped before creating this one.
  </Accordion>

  <Accordion title="REPLICATED" id="replicated-2" defaultOpen>
    The *external table* will be distributed within the database as a
    [replicated](/content/concepts/tables#replicated) *table*.
  </Accordion>

  <Accordion title="TEMP" id="temp-2" defaultOpen>
    The *external table* will be a [memory-only table](/content/concepts/tables_memory_only); which,
    among other things, means it will not be persisted (if the database is restarted, the
    *external table* will be removed), but it will have increased ingest performance.
  </Accordion>

  <Accordion title="LOGICAL" id="logical" defaultOpen>
    External data will **not** be loaded into the database; the data will be retrieved from the
    source upon servicing each query against the *external table*.  This mode ensures queries on
    the *external table* will always return the most current source data, though there will be a
    performance penalty for reparsing & reloading the data from source files upon each query.
  </Accordion>

  <Accordion title="MATERIALIZED" id="materialized" defaultOpen>
    Loads a copy of the external data into the database, refreshed on demand; this is the default
    *external table* type.
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-6" defaultOpen>
    Name of the *schema* that will contain the created *external table*; if no *schema* is specified,
    the *external table* will be created in the user's [default schema](/content/concepts/schemas#schema-default).
  </Accordion>

  <Accordion title="<table name>" id="<table-name>-2" defaultOpen>
    Name of the *external table* to create; must adhere to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria).
  </Accordion>

  <Accordion title="<table definition clause>" id="<table-definition-clause>" defaultOpen>
    Optional clause, defining the structure for the *external table* associated with the source
    data.
  </Accordion>

  <Accordion title="REMOTE QUERY" id="remote-query" defaultOpen>
    Source data specification clause, where `<source data query>` is a SQL query selecting the data
    which will be loaded.

    <Info>
      This clause is mutually exclusive with the `FILE PATHS` clause, and is only
      applicable to JDBC *data sources*.
    </Info>

    The query should meet the following criteria:

    * Any column expression used is given a column alias.
    * The first column is not a `WKT` or unlimited length `VARCHAR` type.
    * The columns and expressions queried should match the intended order, number, & type of the
      columns in the target table.

    Any query resulting in more than *10,000* records will be distributed and loaded in parallel
    (unless directed otherwise) using the following rule sequence:

    1. If `REMOTE_QUERY_NO_SPLIT` is `TRUE`, the query will not be distributed.
    2. If a valid `REMOTE_QUERY_PARTITION_COLUMN` is specified, the query will be distributed by partitioning on the
       given column's values
    3. If a valid `REMOTE_QUERY_ORDER_BY` is specified, the query will be distributed by ordering the data
       accordingly and then partitioning into sequential blocks from the first record
    4. If a non-null numeric/date/time column exists, the query will be distributed by partitioning
       on the first such column's values
    5. The query will be distributed by sorting the data on the first column and then partitioning
       into sequential blocks from the first record

    Type inferencing is limited by the available JDBC types.  To take advantage of Kinetica-specific
    types and properties, define the table columns explicitly in the [\<table definition clause>](/content/sql/ddl#sql-create-ext-table-def).
  </Accordion>

  <Accordion title="FILE PATHS" id="file-paths" defaultOpen>
    Source file specification clause, where `<file paths>` is a comma-separated list of
    single-quoted file paths from which data will be loaded; all files specified are presumed to have
    the same format and data types.

    <Info>
      This clause is mutually exclusive with the `REMOTE QUERY` clause, and is not
      applicable to JDBC *data sources*.
    </Info>

    The form of a file path is dependent on the source referenced:

    * *Data Source*:  If a *data source* is specified in the [load options](/content/sql/ddl#sql-create-ext-table-load-opt), these file paths must resolve
      to accessible files at that *data source* location.  A "path prefix" can be specified instead,
      which will cause all files whose path begins with the given prefix to be included.

      For example, a "path prefix" of `/data/ge` for `<file paths>` would match all of the
      following:

      * `/data/geo.csv`
      * `/data/geo/flights.csv`
      * `/data/geo/2021/airline.csv`

      If using an HDFS *data source*, the "path prefix" must be the name of an HDFS directory.

    * [KiFS](/content/tools/kifs):  The path must resolve to an accessible file path within *KiFS*.
      A "path prefix" can be specified instead, which will cause all files whose path begins with the
      given prefix to be included.

      For example, a "path prefix" of `kifs://data/ge` would match all of the following files under
      the *KiFS* `data` directory:

      * `kifs://data/geo.csv`
      * `kifs://data/geo/flights.csv`
      * `kifs://data/geo/2021/airline.csv`
  </Accordion>

  <Accordion title="FORMAT" id="format" defaultOpen>
    Optional indicator of source file type, for file-based data sources; will be inferred from the
    file extension if not given.

    Supported formats include:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Keyword</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>\[DELIMITED] TEXT</code></td>
            <td>Any text-based, delimited field data file (CSV, PSV, TSV, etc.); a comma-delimited list of options can be given to specify the way in which the data file(s) should be parsed, including the delimiter used, whether headers are present, etc.  Records spanning multiple lines are not supported. See [Delimited Text Options](/content/sql/ddl#sql-create-ext-table-delim-opt) for the complete list of <code>\<delimited text options></code>.</td>
          </tr>

          <tr>
            <td><code>AVRO</code></td>
            <td>*Apache Avro* data file</td>
          </tr>

          <tr>
            <td><code>JSON</code></td>
            <td>Either a *JSON* or *GeoJSON* data file See [JSON/GeoJSON Limitations](/content/load_data/concepts#ingest-json-limitations) for the supported data types.</td>
          </tr>

          <tr>
            <td><code>PARQUET</code></td>
            <td>*Apache Parquet* data file See [Parquet Limitations](/content/load_data/concepts#ingest-parquet-limitations) for the supported data types.</td>
          </tr>

          <tr>
            <td><code>SHAPEFILE</code></td>
            <td>*ArcGIS* shapefile</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="WITH OPTIONS" id="with-options" defaultOpen>
    Optional indicator that a comma-delimited list of connection & global option/value assignments
    will follow.

    See [Load Options](/content/sql/ddl#sql-create-ext-table-load-opt) for the complete list of options.
  </Accordion>

  <Accordion title="<partition clause>" id="<partition-clause>-2" defaultOpen>
    Optional clause, defining a [partitioning](/content/sql/ddl#sql-create-table-partition) scheme for the
    *external table* associated with the source data.
  </Accordion>

  <Accordion title="<tier strategy clause>" id="<tier-strategy-clause>-2" defaultOpen>
    Optional clause, defining the [tier strategy](/content/sql/ddl#sql-create-table-tier-strategy) for the
    *external table* associated with the source data.
  </Accordion>

  <Accordion title="<index clause>" id="<index-clause>-2" defaultOpen>
    Optional clause, applying any number of [column indexes](/content/concepts/indexes#column-index),
    [chunk skip indexes](/content/sql/ddl#sql-alter-table-chunk-skip-index-add),
    [geospatial indexes](/content/sql/ddl#sql-alter-table-geospatial-index-add),
    [CAGRA indexes](/content/sql/ddl#sql-alter-table-cagra-index-add), or
    [HNSW indexes](/content/sql/ddl#sql-alter-table-hnsw-index-add)
    to the *external table* associated with the source data.
  </Accordion>

  <Accordion title="<table property clause>" id="<table-property-clause>-2" defaultOpen>
    Optional clause, assigning table properties, from a subset of those available, to the
    *external table* associated with the source data.
  </Accordion>
</AccordionGroup>

<a id="sql-create-ext-table-delim-opt" />

### Delimited Text Options

The following options can be specified when loading data from delimited text
files.  When reading from multiple files, options specific to the source file
will be applied to each file being read.

<AccordionGroup>
  <Accordion title="COMMENT = '<string>'" id="comment-<string>" defaultOpen>
    Treat lines in the source file(s) that begin with `string` as comments and skip.

    The default comment marker is `#`.
  </Accordion>

  <Accordion title="DELIMITER = '<char>'" id="delimiter-<char>" defaultOpen>
    Use `char` as the source file field delimiter.

    The default delimiter is a comma, unless a source file has one of these extensions:

    * `.psv` - will cause `|` to be the delimiter
    * `.tsv` - will cause the tab character to be the delimiter

    See [Delimited Text Option Characters](/content/sql/ddl#sql-create-ext-table-delim-opt-char) for allowed characters.
  </Accordion>

  <Accordion title="ESCAPE = '<char>'" id="escape-<char>" defaultOpen>
    Use `char` as the source file data escape character.  The escape character preceding any
    other character, in the source data, will be converted into that other character, except
    in the following special cases:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Source Data String</th>
            <th>Representation when Loaded into the Database</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>\<char>a</code></td>
            <td>ASCII bell</td>
          </tr>

          <tr>
            <td><code>\<char>b</code></td>
            <td>ASCII backspace</td>
          </tr>

          <tr>
            <td><code>\<char>f</code></td>
            <td>ASCII form feed</td>
          </tr>

          <tr>
            <td><code>\<char>n</code></td>
            <td>ASCII line feed</td>
          </tr>

          <tr>
            <td><code>\<char>r</code></td>
            <td>ASCII carriage return</td>
          </tr>

          <tr>
            <td><code>\<char>t</code></td>
            <td>ASCII horizontal tab</td>
          </tr>

          <tr>
            <td><code>\<char>v</code></td>
            <td>ASCII vertical tab</td>
          </tr>
        </tbody>
      </table>
    </div>

    For instance, if the escape character is `\`, a `\t` encountered in
    the data will be converted to a tab character when stored in the database.

    The escape character can be used to escape the quoting character, and will be treated as
    an escape character whether it is within a quoted field value or not.

    There is no default escape character.
  </Accordion>

  <Accordion title="HEADER DELIMITER = '<char>'" id="header-delimiter-<char>" defaultOpen>
    Use `char` as the source file header field name/property delimiter, when the source file
    header contains both names and properties.  This is largely specific to the Kinetica
    export to delimited text feature, which will, within each field's header, contain the
    field name and any associated properties, delimited by the pipe `|` character.

    An example *Kinetica* header in a CSV file:

    ```
    id|int|data,category|string|data|char16,name|string|data|char32
    ```

    The default is the `|` (pipe) character.  See
    [Delimited Text Option Characters](/content/sql/load#sql-load-file-server-delim-opt-char) for allowed characters.

    <Info>
      The `DELIMITER` character will still be used to separate
      field name/property sets from each other in the header row
    </Info>
  </Accordion>

  <Accordion title="INCLUDES HEADER = <TRUE|FALSE>" id="includes-header-<true|false>" defaultOpen>
    Declare that the source file(s) will or will not have a header.

    The default is `TRUE`.
  </Accordion>

  <Accordion title="NULL = '<string>'" id="null-<string>" defaultOpen>
    Treat `string` as the indicator of a null source field value.

    The default is the empty string.
  </Accordion>

  <Accordion title="QUOTE = '<char>'" id="quote-<char>" defaultOpen>
    Use `char` as the source file data quoting character, for enclosing field values.
    Usually used to wrap field values that contain embedded delimiter characters, though any
    field may be enclosed in quote characters *(for clarity, for instance)*.  The quote
    character must appear as the first and last character of a field value in order to be
    interpreted as quoting the value.  Within a quoted value, embedded quote characters may be
    escaped by preceding them with another quote character or the escape character specified
    by `ESCAPE`, if given.

    The default is the `"` (double-quote) character.  See
    [Delimited Text Option Characters](/content/sql/ddl#sql-create-ext-table-delim-opt-char) for allowed characters.
  </Accordion>
</AccordionGroup>

<a id="sql-create-ext-table-delim-opt-char" />

#### Delimited Text Option Characters

For `DELIMITER`, `HEADER DELIMITER`, `ESCAPE`, & `QUOTE`, any single
character can be used, or any one of the following escaped characters:

| Escaped Char | Corresponding Source File Character |
| ------------ | ----------------------------------- |
| `''`         | Single quote                        |
| `\a`         | ASCII bell                          |
| `\b`         | ASCII backspace                     |
| `\f`         | ASCII form feed                     |
| `\t`         | ASCII horizontal tab                |
| `\v`         | ASCII vertical tab                  |

For instance, if two single quotes (`''`) are specified for a `QUOTE`
character, the parser will interpret *single quotes* in the source file as
*quoting* characters; specifying `\t` for `DELIMITER` will cause the parser
to interpret *ASCII horizontal tab* characters in the source file as *delimiter*
characters.

<a id="sql-create-ext-table-load-opt" />

### Load Options

The following options can be specified to modify the way data is loaded (or not
loaded) into the target table.

<AccordionGroup>
  <Accordion title="BAD RECORD TABLE" id="bad-record-table" defaultOpen>
    Name of the table containing records that failed to be loaded into the target table.  This
    bad record table will include the following columns:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Column Name</th>
            <th>Source Data Format Codes</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>line\_number</code></td>
            <td>Number of the line in the input file containing the failed record</td>
          </tr>

          <tr>
            <td><code>char\_number</code></td>
            <td>Position of character within a failed record that is assessed as the beginning of the portion of the record that failed to process</td>
          </tr>

          <tr>
            <td><code>filename</code></td>
            <td>Name of file that contained the failed record</td>
          </tr>

          <tr>
            <td><code>line\_rejected</code></td>
            <td>Text of the record that failed to process</td>
          </tr>

          <tr>
            <td><code>error\_msg</code></td>
            <td>Error message associated with the record processing failure</td>
          </tr>
        </tbody>
      </table>
    </div>

    <Info>
      This option is not applicable for an `ON ERROR` mode of `ABORT`.  In that
      mode, processing stops at the first error and that error is returned to the user.
    </Info>
  </Accordion>

  <Accordion title="BATCH SIZE" id="batch-size" defaultOpen>
    Use an ingest batch size of the given number of records.

    The default batch size is *50,000*.
  </Accordion>

  <Accordion title="COLUMN FORMATS" id="column-formats" defaultOpen>
    Use the given type-specific formatting for the given column when parsing source data being
    loaded into that column.  This should be a map of column names to format specifications,
    where each format specification is map of column type to data format, all formatted as a
    JSON string.

    Supported column types include:

    <Tabs>
      <Tab title="date">
        Apply the given date format to the given column.

        Common date format codes follow.  For the complete list, see
        [Date/Time Conversion Codes](/content/sql/query#sql-datetime-conversion-codes).

        <div>
          <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
            <thead>
              <tr>
                <th>Code</th>
                <th>Description</th>
              </tr>
            </thead>

            <tbody>
              <tr>
                <td><code>YYYY</code></td>
                <td>4-digit year</td>
              </tr>

              <tr>
                <td><code>MM</code></td>
                <td>2-digit month, where *January* is <code>01</code></td>
              </tr>

              <tr>
                <td><code>DD</code></td>
                <td>2-digit day of the month, where the *1st* of each month is <code>01</code></td>
              </tr>
            </tbody>
          </table>
        </div>
      </Tab>

      <Tab title="time">
        Apply the given time format to the given column.

        Common time format codes follow.  For the complete list, see
        [Date/Time Conversion Codes](/content/sql/query#sql-datetime-conversion-codes).

        <div>
          <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
            <thead>
              <tr>
                <th>Code</th>
                <th>Description</th>
              </tr>
            </thead>

            <tbody>
              <tr>
                <td><code>HH24</code></td>
                <td>24-based hour, where *12:00 AM* is <code>00</code> and *7:00 PM* is <code>19</code></td>
              </tr>

              <tr>
                <td><code>MI</code></td>
                <td>2-digit minute of the hour</td>
              </tr>

              <tr>
                <td><code>SS</code></td>
                <td>2-digit second of the minute</td>
              </tr>

              <tr>
                <td><code>MS</code></td>
                <td>milliseconds</td>
              </tr>
            </tbody>
          </table>
        </div>
      </Tab>

      <Tab title="datetime">
        Apply the given date/time format to the given column.
      </Tab>
    </Tabs>

    For example, to load dates of the format `2010.10.30` into date column *d* and times of
    the 24-hour format `18:36:54.789` into time column *t*:

    ```
    {
        "d": {"date": "YYYY.MM.DD"},
        "t": {"time": "HH24:MI:SS.MS"}
    }
    ```

    <Info>
      This option is not available for *data sources* configured for *JDBC*.
    </Info>
  </Accordion>

  <Accordion title="DATA SOURCE" id="data-source" defaultOpen>
    Load data from the given [data source](/content/sql/ddl#sql-create-data-source).
    [Data source connect privilege](/content/sql/security#sql-security-priv-mgmt-ds-grant) is required when
    loading from a *data source*.
  </Accordion>

  <Accordion title="DEFAULT COLUMN FORMATS" id="default-column-formats" defaultOpen>
    Use the given formats for source data being loaded into target table columns with the
    corresponding column types.   This should be a map of target column type to source format
    for data being loaded into columns of that type, formatted as a JSON string.

    Supported column properties and source data formats are the same as those
    listed in the description of the `COLUMN FORMATS` option.

    For example, to make the default format for loading source data dates like `2010.10.30`
    and 24-hour times like `18:36:54.789`:

    ```
    {
        "date": "YYYY.MM.DD",
        "time": "HH24:MI:SS.MS",
        "datetime": "YYYY.MM.DD HH24:MI:SS.MS"
    }
    ```

    <Info>
      This option is not available for *data sources* configured for *JDBC*.
    </Info>
  </Accordion>

  <Accordion title="FIELDS IGNORED BY" id="fields-ignored-by" defaultOpen>
    Choose a comma-separated list of fields from the source file(s) to ignore, loading only
    those fields that are not in the identified list in the order they appear in the file.
    Fields can be identified by either `POSITION` or `NAME`.  If ignoring by `NAME`, the
    specified names must match the source file field names exactly.

    * Identifying by Name:

      ```
      FIELDS IGNORED BY NAME(Category, Description)
      ```
    * Identifying by Position:

      ```
      FIELDS IGNORED BY POSITION(3, 4)
      ```

    <Info>
      - When ignoring source data file fields, the set of fields that are not ignored must
        align, in type & number in their order in the source file, with the *external table*
        columns into which the data will be loaded.
      - Ignoring fields by `POSITION` is only supported for delimited text files.
    </Info>
  </Accordion>

  <Accordion title="FIELDS MAPPED BY" id="fields-mapped-by" defaultOpen>
    Choose a comma-separated list of fields from the source file(s) to load, in the specified
    order, identifying fields by either `POSITION` or `NAME`.  If mapping by `NAME`, the
    specified names must match the source file field names exactly.

    * Identifying by Name:

      ```
      FIELDS MAPPED BY NAME(ID, Name, Stock)
      ```
    * Identifying by Position:

      ```
      FIELDS MAPPED BY POSITION(1, 2, 5)
      ```

    <Info>
      - When mapping source data file fields, the set of fields that are identified must
        align, in type & number in the specified order, with the *external table* columns into
        which data will be loaded.
      - Mapping fields by `POSITION` is only supported for delimited text files.
    </Info>
  </Accordion>

  <Accordion title="FLATTEN_COLUMNS" id="flatten_columns" defaultOpen>
    Specify the policy for handling nested columns within JSON data.

    The default is `FALSE`.

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Value</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>TRUE</code></td>
            <td>Break up nested columns into multiple columns.</td>
          </tr>

          <tr>
            <td><code>FALSE</code></td>
            <td>Treat nested columns as JSON columns instead of flattening.</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="IGNORE_EXISTING_PK" id="ignore_existing_pk" defaultOpen>
    Specify the error suppression policy for inserting duplicate primary key values into a
    table with a primary key.  If the specified table does not have a primary key or the
    `UPDATE_ON_EXISTING_PK` option is used, then this options has no effect.

    The default is `FALSE`.

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Value</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>TRUE</code></td>
            <td>Suppress errors when inserted records and existing records' PKs match.</td>
          </tr>

          <tr>
            <td><code>FALSE</code></td>
            <td>Return errors when inserted records and existing records' PKs match.</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="INGESTION MODE" id="ingestion-mode" defaultOpen>
    Whether to do a full ingest of the data or perform a *dry run* or *type inference* instead.

    The default mode is `FULL`.

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Value</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>DRY RUN</code></td>
            <td>No data will be inserted, but the file will be read with the applied <code>ON ERROR</code> mode and the number of valid records that would normally be inserted is returned.</td>
          </tr>

          <tr>
            <td><code>FULL</code></td>
            <td>Data is fully ingested according to the active <code>ON ERROR</code> mode.</td>
          </tr>

          <tr>
            <td><code>TYPE INFERENCE</code></td>
            <td>Infer the type of the source data and return, without ingesting any data. The inferred type is returned in the response, as the output of a <code>SHOW TABLE</code> command.</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="JDBC_FETCH_SIZE" id="jdbc_fetch_size" defaultOpen>
    Retrieve this many records at a time from the remote database.  Lowering this number will
    help tables with large record sizes fit into available memory during ingest.

    The default is *50,000*.

    <Info>
      This option is only available for *data sources* configured for *JDBC*.
    </Info>
  </Accordion>

  <Accordion title="NUM_SPLITS_PER_RANK" id="num_splits_per_rank" defaultOpen>
    The number of remote query partitions to assign each *Kinetica* worker process.  The
    queries assigned to a worker process will be executed by the tasks allotted to the process.

    To decrease memory pressure, increase the number of splits per rank.

    The default is *8* splits per rank.

    <Info>
      This option is only available for *data sources* configured for *JDBC*.
    </Info>
  </Accordion>

  <Accordion title="NUM_TASKS_PER_RANK" id="num_tasks_per_rank" defaultOpen>
    The number of tasks to use on each *Kinetica* worker process to process remote queries.
    The tasks assigned to a worker process will execute any remote query partitions assigned to
    it.

    To decrease memory pressure, decrease the number of tasks per rank.

    The default is *8* tasks per rank.

    <Info>
      This option is only available for *data sources* configured for *JDBC*.
    </Info>
  </Accordion>

  <Accordion title="JDBC_SESSION_INIT_STATEMENT" id="jdbc_session_init_statement" defaultOpen>
    Run the single given statement before the initial load is performed and also before each
    subsequent reload, if `REFRESH ON START` or `SUBSCRIBE` is `TRUE`.

    For example, to set the time zone to *UTC* before running each load, use:

    ```
    JDBC_SESSION_INIT_STATEMENT = 'SET TIME ZONE ''UTC'''
    ```

    <Info>
      This option is only available for *data sources* configured for *JDBC*.
    </Info>
  </Accordion>

  <Accordion title="ON ERROR" id="on-error" defaultOpen>
    When an error is encountered loading a record, handle it using either of the
    following modes.  The default mode is `ABORT`.

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Value</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>SKIP</code></td>
            <td>If an error is encountered parsing a source record, skip the record.</td>
          </tr>

          <tr>
            <td><code>ABORT</code></td>
            <td>If an error is encountered parsing a source record, stop the data load process.  Primary key collisions are considered abortable errors in this mode.</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="POLL_INTERVAL" id="poll_interval" defaultOpen>
    Interval, in seconds, at which a *data source* is polled for updates.  The number of
    seconds must be passed as a single-quoted string.

    The default interval is *60* seconds.  This option is only applicable when `SUBSCRIBE` is
    `TRUE`.
  </Accordion>

  <Accordion title="REFRESH ON START" id="refresh-on-start" defaultOpen>
    Whether to refresh the *external table* data upon restart of the database.  Only relevant
    for *materialized external tables*.

    The default is `FALSE`.  This option is ignored if `SUBSCRIBE` is `TRUE`.

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Value</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>TRUE</code></td>
            <td>Refresh the *external table's* data when the database is restarted.</td>
          </tr>

          <tr>
            <td><code>FALSE</code></td>
            <td>Do not refresh the *external table's* data when the database is restarted.</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="REMOTE_QUERY_INCREASING_COLUMN" id="remote_query_increasing_column" defaultOpen>
    For a JDBC query *change data capture* loading scheme, the remote query column that will be
    used to determine whether a record is new and should be loaded or not.  This column should
    have an ever-increasing value and be of an integral or date/timestamp type.  Often, this
    column will be a sequence-based ID or create/modify timestamp.

    This option is only applicable when `SUBSCRIBE` is `TRUE`.

    <Info>
      This option is only available for *data sources* configured for *JDBC*.
    </Info>
  </Accordion>

  <Accordion title="REMOTE_QUERY_NO_SPLIT" id="remote_query_no_split" defaultOpen>
    Whether to not distribute the retrieval of remote data and issue queries for blocks of data
    at time in parallel.

    The default is `FALSE`.

    <Info>
      This option is only available for *data sources* configured for *JDBC*
    </Info>

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Value</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>TRUE</code></td>
            <td>Issue the remote data retrieval as a single query.</td>
          </tr>

          <tr>
            <td><code>FALSE</code></td>
            <td>Distribute and parallelize the remote data retrieval in queries for blocks of data at a time.</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="REMOTE_QUERY_ORDER_BY" id="remote_query_order_by" defaultOpen>
    Ordering expression to use in partitioning remote data for retrieval.  The remote data will
    be ordered according to this expression and then retrieved in sequential blocks from the
    first record.  This is potentially less performant than using `REMOTE_QUERY_PARTITION_COLUMN`.

    If `REMOTE_QUERY_NO_SPLIT` is `TRUE`, a valid `REMOTE_QUERY_PARTITION_COLUMN` is specified, or the column given is
    invalid, this option is ignored.

    <Info>
      This option is only available for *data sources* configured for *JDBC*
    </Info>
  </Accordion>

  <Accordion title="REMOTE_QUERY_PARTITION_COLUMN" id="remote_query_partition_column" defaultOpen>
    Column to use to partition remote data for retrieval.  The column must be numeric and
    should be relatively evenly distributed so that queries using values of this column to
    partition data will retrieve relatively consistently-sized result sets.

    If `REMOTE_QUERY_NO_SPLIT` is `TRUE` or the column given is invalid, this option is ignored.

    <Info>
      This option is only available for *data sources* configured for *JDBC*
    </Info>
  </Accordion>

  <Accordion title="SUBSCRIBE" id="subscribe" defaultOpen>
    Whether to subscribe to the [data source](/content/sql/ddl#sql-create-data-source) specified in the
    `DATA SOURCE` option.  Only relevant for *materialized external tables* using
    *data sources* configured to allow streaming.

    The default is `FALSE`.  If `TRUE`, the `REFRESH ON START` option is ignored.

    <Info>
      This option is not available for *data sources* configured for *HDFS*.
    </Info>

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Value</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>TRUE</code></td>
            <td>Subscribe to the specified *streaming data source*.</td>
          </tr>

          <tr>
            <td><code>FALSE</code></td>
            <td>Do not subscribe to the specified *data source*.</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="TRUNCATE_STRINGS" id="truncate_strings" defaultOpen>
    Specify the string truncation policy for inserting text into `VARCHAR` columns that are
    not large enough to hold the entire text value.

    The default is `FALSE`.

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Value</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>TRUE</code></td>
            <td>Truncate any inserted string value at the maximum size for its column.</td>
          </tr>

          <tr>
            <td><code>FALSE</code></td>
            <td>Reject any record with a string value that is too long for its column.</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="TYPE_INFERENCE_MODE" id="type_inference_mode" defaultOpen>
    When making a type inference of the data values in order to define column types for the
    target table, use one of the following modes.

    The default mode is `SPEED`.

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Value</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>ACCURACY</code></td>
            <td>Scan all available data to arrive at column types that are the narrowest possible that can still hold all the data.</td>
          </tr>

          <tr>
            <td><code>SPEED</code></td>
            <td>Pick the widest possible column types from the minimum data scanned in order to quickly arrive at column types that should fit all data values.</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="UPDATE_ON_EXISTING_PK" id="update_on_existing_pk" defaultOpen>
    Specify the record collision policy for inserting into a table with a primary key.
    If the specified table does not have a primary key, then this options has no effect.

    The default is `FALSE`.

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Value</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>TRUE</code></td>
            <td>Update existing records with records being inserted, when PKs match.</td>
          </tr>

          <tr>
            <td><code>FALSE</code></td>
            <td>Discard records being inserted when existing records' PKs match.</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>
</AccordionGroup>

<a id="sql-create-ext-table-def" />

### Table Definition Clause

The *table definition clause* allows for an explicit local table structure to be
defined, irrespective of the source data type.  This specification mirrors that
of [CREATE TABLE](/content/sql/ddl#sql-create-table).

```sql title="Table Definition Clause Syntax" theme={null}
(
    <column name> <column definition> [COMMENT '<column comment>'],
    ...
    <column name> <column definition> [COMMENT '<column comment>'],
    [PRIMARY KEY (<column list>)],
    [SHARD KEY (<column list>)],
    [FOREIGN KEY
        (<column list>) REFERENCES <foreign table name>(<foreign column list>) [AS <foreign key name>],
        ...
        (<column list>) REFERENCES <foreign table name>(<foreign column list>) [AS <foreign key name>]
    ]
)
```

See [Data Definition (DDL)](/content/sql/ddl#sql-ddl) for column format.

<a id="sql-create-ext-table-partition" />

### Partition Clause

An *external table* can be further segmented into *partitions*.

The supported *Partition Clause* syntax & features are the same as those in the
[CREATE TABLE Partition Clause](/content/sql/ddl#sql-create-table-partition).

<a id="sql-create-ext-table-tier-strategy" />

### Tier Strategy Clause

An *external table* can have a [tier strategy](/content/rm/concepts#rm-concepts-tier-strategy)
specified at creation time.  If not assigned a *tier strategy* upon creation, a
[default tier strategy](/content/rm/configuration#rm-config-tier-strategy-default)
will be assigned.

The supported *Tier Strategy Clause* syntax & features are the same as those in
the [CREATE TABLE Tier Strategy Clause](/content/sql/ddl#sql-create-table-tier-strategy).

<a id="sql-create-ext-table-index" />

### Index Clause

An *external table* can have any number of indexes applied to any of its columns
at creation time.

The supported *Index Clause* syntax & features are the same as those in the
[CREATE TABLE Index Clause](/content/sql/ddl#sql-create-table-index).

<a id="sql-create-ext-table-prop" />

### Table Property Clause

A subset of *table* properties can be applied to the *external table* associated
with the external data at creation time.

The supported *Table Property Clause* syntax & features are the same as those in
the [CREATE TABLE Table Property Clause](/content/sql/ddl#sql-create-table-prop).

<a id="sql-create-ext-table-examples" />

### Examples

To create a *logical external table* with the following features, using a query
as the source of data:

* External table named `ext_employee_dept2` in the `example` schema
* Source is `department` *2* employees from the `example.employee` table,
  queried through the <Badge color="gray">example.jdbc\_ds</Badge> data source
* Data is re-queried from the source each time the *external table* is queried

```sql CREATE LOGICAL EXTERNAL TABLE theme={null}
CREATE LOGICAL EXTERNAL TABLE example.ext_employee_dept2
REMOTE QUERY 'SELECT * FROM example.employee WHERE dept_id = 2'
WITH OPTIONS (DATA SOURCE = 'example.jdbc_ds')
```

To create an *external table* with the following features, using *KiFS* as the
source of data:

* External table named `ext_product` in the `example` schema
* External source is a *KiFS* file named `product.csv` located in the `data`
  directory
* Data is not refreshed on database startup

```sql CREATE EXTERNAL TABLE with Default Options theme={null}
CREATE EXTERNAL TABLE example.ext_product
FILE PATHS 'kifs://data/products.csv'
```

To create an *external table* with the following features, using *KiFS* as the
source of data:

* External table named `ext_employee` in the `example` schema
* External source is a *Parquet* file named `employee.parquet` located in the
  *KiFS* directory `data`
* External table has a *primary key* on the `id` column
* Data is not refreshed on database startup

```sql CREATE EXTERNAL TABLE with Parquet File Example theme={null}
CREATE EXTERNAL TABLE example.ext_employee
FILE PATHS 'kifs://data/employee.parquet'
WITH OPTIONS (PRIMARY KEY = (id))
```

To create an *external table* with the following features, using *KiFS* as the
source of data:

* External table named `ext_employee` in the `example` schema
* External source is a file named `employee.csv` located in the
  *KiFS* directory `data`
* Apply a date format to the `hire_date` column

```sql CREATE EXTERNAL TABLE with Date Format Example theme={null}
CREATE EXTERNAL TABLE example.ext_employee
FILE PATHS 'kifs://data/employee.csv'
WITH OPTIONS
(
	COLUMN FORMATS = '
	{
		"hire_date": {"date": "YYYY-MM-DD"}
	}'
)
```

To create an *external table* with the following features, using a *data source*
as the source of data:

* External table named `ext_product` in the `example` schema
* External source is a *data source* named `product_ds` in the `example`
  schema
* Source is a file named `products.csv`
* Data is refreshed on database startup

```sql CREATE EXTERNAL TABLE with Data Source Example theme={null}
CREATE EXTERNAL TABLE example.ext_product
FILE PATHS 'products.csv'
WITH OPTIONS
(
	DATA SOURCE = 'example.product_ds',
	REFRESH ON START = TRUE
)
```

To create an *external table* with the following features, subscribing to a
*data source*:

* External table named `ext_product` in the `example` schema
* External source is a *data source* named `product_ds` in the `example`
  schema
* Source is a file named `products.csv`
* Data updates are streamed continuously

```sql CREATE EXTERNAL TABLE with Data Source Subscription Example theme={null}
CREATE EXTERNAL TABLE example.ext_product
FILE PATHS 'products.csv'
WITH OPTIONS
(
	DATA SOURCE = 'example.product_ds',
	SUBSCRIBE = TRUE,
	POLL_INTERVAL = '60'
)
```

To create an *external table* with the following features, using a remote query
through a JDBC *data source* as the source of data:

* External table named `ext_employee_dept2` in the `example` schema
* External source is a *data source* named `jdbc_ds` in the `example`
  schema
* Source data is a remote query of employees in department *2* from that
  database's `example.ext_employee` table
* Data is refreshed on database startup

```sql CREATE EXTERNAL TABLE with JDBC Data Source Remote Query Example theme={null}
CREATE EXTERNAL TABLE example.ext_employee_dept2
REMOTE QUERY 'SELECT * FROM example.ext_employee WHERE dept_id = 2'
WITH OPTIONS
(
	DATA SOURCE = 'example.jdbc_ds',
	REFRESH ON START = TRUE
)
```

#### Data Sources

<p><strong>File-Based</strong></p>

To create an external table that loads a CSV file, <Badge color="gray">products.csv</Badge>,
from the *data source* <Badge color="gray">example.product\_ds</Badge>, into a table named
`example.ext_product`:

```sql CREATE EXTERNAL TABLE Data Source File Example theme={null}
CREATE EXTERNAL TABLE example.ext_product
FILE PATHS 'products.csv'
WITH OPTIONS (DATA SOURCE = 'example.product_ds')
```

<p><strong>Query-Based</strong></p>

To create an external table that is the result of a remote query of employees in
department *2* from the JDBC *data source* <Badge color="gray">example.jdbc\_ds</Badge>, into
a local table named `example.ext_employee_dept2`:

```sql CREATE EXTERNAL TABLE Data Source Query Example theme={null}
CREATE EXTERNAL TABLE example.ext_employee_dept2
REMOTE QUERY 'SELECT * FROM example.employee WHERE dept_id = 2'
WITH OPTIONS (DATA SOURCE = 'example.jdbc_ds')
```

#### Change Data Capture

<p><strong>File-Based</strong></p>

To create an external table loaded by a set of order data in a change data
capture scheme with the following conditions:

* data pulled through a *data source*, <Badge color="gray">example.order\_ds</Badge>
* data files contained with an <Badge color="gray">orders</Badge> directory
* initially, all files in the directory will be loaded; subsequently, only those
  files that have been updated since the last check will be reloaded
* files will be polled for updates every *60* seconds
* target table named `example.ext_order`

```sql CREATE EXTERNAL TABLE File Change Data Capture Example theme={null}
CREATE EXTERNAL TABLE example.ext_order
FILE PATHS 'orders/'
WITH OPTIONS (DATA SOURCE = 'example.order_ds', SUBSCRIBE = TRUE)
```

<p><strong>Query-Based</strong></p>

To create an external table loaded from a remote query of orders in a change
data capture scheme with the following conditions:

* data pulled through a *data source*, <Badge color="gray">example.jdbc\_ds</Badge>
* data contained with an `example.orders` table, where only orders for product
  with ID *42* will be loaded into the target table
* initially, all orders will be loaded; subsequently, only those orders with an
  `order_id` column value higher than the highest one on the previous poll
  cycle will be loaded
* remote table will be polled for updates every *60* seconds
* target table named `example.ext_order_product42`

```sql CREATE EXTERNAL TABLE Query Change Data Capture Example theme={null}
-- Load new orders for product 42 continuously into a table
--   order_id is an ever-increasing sequence allotted to each new order
CREATE EXTERNAL TABLE example.ext_order_product42
REMOTE QUERY 'SELECT * FROM example.orders WHERE product_id = 42'
WITH OPTIONS
(
	DATA SOURCE = 'example.jdbc_ds',
	SUBSCRIBE = TRUE,
	REMOTE_QUERY_INCREASING_COLUMN = 'order_id'
)
```

<a id="sql-create-table-as" />

## CREATE TABLE ... AS

Creates a new *table* from the given query in the specified
[schema](/content/sql/ddl#sql-create-schema).

```sql title="CREATE TABLE ... AS Syntax" theme={null}
CREATE [OR REPLACE] [REPLICATED] [TEMP] TABLE [<schema name>.]<table name> AS
(
    <select statement>
)
```

Any column aliases used must adhere to the supported
[naming criteria](/content/sql/naming#sql-naming-criteria).

While [primary keys](/content/concepts/tables#primary-key) & [foreign keys](/content/concepts/tables#foreign-key) are
not transferred to the new table, [shard keys](/content/concepts/tables#shard-key) will be, if the
column(s) composing them are part of the `SELECT` list.

### Parameters

| Parameter/Key        | Description                                                                                                                                                                                                                                           |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `OR REPLACE`         | Any existing *table* or *view* with the same name will be dropped before creating this one                                                                                                                                                            |
| `REPLICATED`         | The *table* will be distributed within the database as a [replicated](/content/concepts/tables#replicated) *table*                                                                                                                                    |
| `TEMP`               | The *table* will be a [memory-only table](/content/concepts/tables_memory_only); which, among other things, means it will not be persisted (if the database is restarted, the *table* will be removed), but it will have increased ingest performance |
| `<schema name>`      | Name of the *schema* that will contain the created *table*; if no *schema* is specified, the *table* will be created in the user's [default schema](/content/concepts/schemas#schema-default)                                                         |
| `<table name>`       | Name of the *table* to create; must adhere to supported [naming criteria](/content/sql/naming#sql-naming-criteria)                                                                                                                                    |
| `<select statement>` | The query that will define both the initial structure and content of the created *table*                                                                                                                                                              |

The following can be applied to `<select statement>` to affect the resulting
table:

| Keyword                                                                      | Type                 | Description                                                                                                                                                      |
| ---------------------------------------------------------------------------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [KI\_HINT\_GROUP\_BY\_PK](/content/sql/query#sql-hints)                      | *hint*               | Creates a [primary keys](/content/concepts/tables#primary-key) on the columns in the `GROUP BY` clause if the outermost `SELECT` statement contains a `GROUP BY` |
| [KI\_HINT\_INDEX(column list)](/content/sql/query#sql-hints)                 | *hint*               | Indexes each of the columns specified in the column list                                                                                                         |
| [KI\_SHARD\_KEY(column list)](/content/sql/query#sql-distribution-functions) | *pseudo-* *function* | Shards the result table with a [shard key](/content/concepts/tables#shard-key) composed of all columns in the specified column list                              |

### Examples

To create a replicated temporary table that is a copy of an
existing table, failing if a table with the same name as the target table
already exists:

```sql CREATE TABLE ... AS (Replicated/Temporary) Example theme={null}
CREATE REPLICATED TEMP TABLE example.new_temporary_table AS
(
    SELECT *
    FROM example.old_table
)
```

To create a permanent table with columns `a`, `b`, `c`, & `d` a new
*shard key* on columns `a` & `b`, and an index on column `d`, replacing a
table with the same name as the target table, if it exists:

```sql CREATE TABLE ... AS (Reshard) Example theme={null}
CREATE OR REPLACE TABLE example.new_sharded_table AS
(
    SELECT a, b, c, d, KI_SHARD_KEY(a, b) /* KI_HINT_INDEX(d) */
    FROM example.old_table
)
```

To copy a table with columns `a`, `b`, `c`, & `d`, preserving the
*primary key* on `a`, `b`, & `c`, and the *foreign key* from `d`; a new
table must be created to match the schema of the old one and then records can be
copied from the old one to the new one:

```sql CREATE TABLE (Preserve Primary Key) Example, DDL Step theme={null}
CREATE TABLE example.new_pk_copy_table
(
    a INTEGER NOT NULL,
    b INTEGER NOT NULL,
    c VARCHAR(32) NOT NULL,
    d TIMESTAMP,
    PRIMARY KEY (a, b, c),
    FOREIGN KEY (d) REFERENCES example.old_table_lookup(d)
)
```

```sql CREATE TABLE (Preserve Primary Key) Example, DML Step theme={null}
INSERT INTO example.new_pk_copy_table
SELECT *
FROM example.old_table
```

<Info>
  This create/insert process is necessary, as neither *primary keys* nor
  *foreign keys* can be preserved through hints.
</Info>

See [Limitations](/content/sql/limit#sql-limitations) for other restrictions.

<a id="sql-alter-table" />

## ALTER TABLE

Alters the configuration of a [table](/content/sql/ddl#sql-create-table).

Any of the following facets of a table can be altered:

* [Name](/content/sql/ddl#sql-alter-table-rename)
* [Schema](/content/sql/ddl#sql-alter-table-move)
* [Access Mode](/content/sql/ddl#sql-alter-table-set-access-mode)
* [TTL](/content/sql/ddl#sql-alter-table-set-ttl)
* [Columns](/content/sql/ddl#sql-alter-table-column-add)
* [Column Indexes](/content/sql/ddl#sql-alter-table-column-index-add)
* [Low-Cardinality Indexes](/content/sql/ddl#sql-alter-table-low-cardinality-index-add)
* [Chunk Skip Indexes](/content/sql/ddl#sql-alter-table-chunk-skip-index-add)
* [Geospatial Indexes](/content/sql/ddl#sql-alter-table-geospatial-index-add)
* [CAGRA Indexes](/content/sql/ddl#sql-alter-table-cagra-index-add)
* [HNSW Indexes](/content/sql/ddl#sql-alter-table-hnsw-index-add)
* [Foreign Keys](/content/sql/ddl#sql-alter-table-foreign-key-add)
* [Partitions](/content/sql/ddl#sql-alter-table-partition-add)
* [Tier Strategy](/content/sql/ddl#sql-alter-table-set-tier-strategy)
* [External Data Source Subscription](/content/sql/ddl#sql-alter-table-manage-sub)

<a id="sql-alter-table-rename" />

### Rename Table

A table can be renamed, following the supported
[naming criteria](/content/sql/naming#sql-naming-criteria).

```sql title="Rename Table Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
RENAME TO <new table name>
```

All dependent [views](/content/sql/ddl#sql-create-view),
[materialized views](/content/sql/ddl#sql-create-materialized-view),
[streams](/content/sql/ddl#sql-create-stream), and
[SQL procedures](/content/sql/procedure#sql-procedures) will be dropped.

<Info>
  Any *tables* with [foreign keys](/content/concepts/tables#foreign-key) that
  target this *table* must be dropped before it can be renamed.
</Info>

<a id="sql-alter-table-move" />

### Move Table

A table can be moved from one schema to another.

```sql title="Move Table Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
< MOVE TO | SET SCHEMA > <other schema name>
```

All dependent [views](/content/sql/ddl#sql-create-view),
[materialized views](/content/sql/ddl#sql-create-materialized-view),
[streams](/content/sql/ddl#sql-create-stream), and
[SQL procedures](/content/sql/procedure#sql-procedures) will be dropped.

<Info>
  Any *tables* with [foreign keys](/content/concepts/tables#foreign-key) that
  target this *table* must be dropped before it can be moved.
</Info>

For example, to move the `sales_2017` table from the `example_olap` schema
to the `example_archive` schema:

```sql Move Table Example theme={null}
ALTER TABLE example_olap.sales_2017
MOVE TO example_archive
```

<a id="sql-alter-table-set-access-mode" />

### Set Access Mode

A table can have its global accessibility modified for all users in the system,
independently from and further restricting any role-based access controls in
place.  Note that changing the access mode cannot *widen* access for users not
already granted access; it can only *narrow* access for those who already have
access.  This setting will also trump administrative access to a table.

```sql title="Set Table Access Mode Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
SET ACCESS MODE < NO_ACCESS | READ_ONLY | WRITE_ONLY | READ_WRITE >
```

<a id="sql-alter-table-set-ttl" />

### Set TTL

A table's [time-to-live (TTL)](/content/concepts/ttl) can be altered.

```sql title="Set Table TTL Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
SET TTL <new ttl>
```

For example, to set a *TTL* of *7* minutes on a table:

```sql Set Table TTL Example theme={null}
ALTER TABLE example.employee
SET TTL 7
```

To set a table to never expire by *TTL* timeout:

```sql Set Table No Expiration Example theme={null}
ALTER TABLE example.employee
SET TTL -1
```

<a id="sql-alter-table-column-add" />

### Add Column

A column can be added, specifying a [column definition](/content/sql/ddl#sql-ddl).

```sql title="Add Table Column Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
ADD <column name> <column definition> [DEFAULT <string/numeric constant | column name>]
```

A new column can have its values initially populated through the use of the
`DEFAULT` keyword.  These values can either be a string/numeric constant or
the name of an existing column in the table from which values can be copied into
the new column.  This default value is only in effect for the column creation;
the new column will have no default value after that.

**Examples**

To add, to the `employee` table, a `salary` column that is a non-nullable,
10-digit number field containing 2 decimal places with a default value of `0`:

```sql Add Table Column (Numeric) Example theme={null}
ALTER TABLE example.employee
ADD salary NUMERIC(10, 2) NOT NULL DEFAULT 0
```

To add, to the `employee` table, a `category` column that is a nullable,
[dictionary-encoded](/content/concepts/dictionary_encoding), 32-character text
field:

```sql Add Table Column (CharN/Dictionary-Encoded) Example theme={null}
ALTER TABLE example.employee
ADD category VARCHAR(32, DICT)
```

To add, to the `employee` table, a `bio` column that is a nullable,
[text-searchable](/content/concepts/types#types-data-handling), unrestricted-width text field:

```sql Add Table Column (String/Text-Searchable) Example theme={null}
ALTER TABLE example.employee
ADD bio VARCHAR(TEXT_SEARCH)
```

<a id="sql-alter-table-column-rename" />

### Rename Column

An existing column can be renamed.

```sql title="Rename Table Column Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
RENAME COLUMN <column current name> TO <column new name>
```

All dependent [views](/content/sql/ddl#sql-create-view),
[materialized views](/content/sql/ddl#sql-create-materialized-view),
[streams](/content/sql/ddl#sql-create-stream), and
[SQL procedures](/content/sql/procedure#sql-procedures) will be dropped.

<Info>
  Any *tables* with [foreign keys](/content/concepts/tables#foreign-key) that
  target the column being renamed must be dropped before it can be renamed.
</Info>

```sql Rename Table Column Example theme={null}
ALTER TABLE example.employee
RENAME COLUMN bio TO biography
```

<a id="sql-alter-table-column-modify" />

### Modify Column

A column can have its [column definition](/content/sql/ddl#sql-ddl) modified, affecting
*column type*, *column size*, *column properties*, and nullability.

```sql title="Modify Table Column Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
MODIFY [COLUMN] <column name> <column definition>
```

```sql title="Modify Table Column Alternate Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
ALTER COLUMN <column name> <column definition>
```

All dependent [views](/content/sql/ddl#sql-create-view),
[materialized views](/content/sql/ddl#sql-create-materialized-view),
[streams](/content/sql/ddl#sql-create-stream), and
[SQL procedures](/content/sql/procedure#sql-procedures) will be dropped.

<Info>
  Any *tables* with [foreign keys](/content/concepts/tables#foreign-key) that
  target the column being modified must be dropped before it can be modified.
</Info>

If a column is modified to be non-nullable, it will be populated with default
values--empty string for string fields and `0` for numeric fields.

**Examples**

To change, in the `employee` table, the `first_name` column to one that is a
non-nullable, [dictionary-encoded](/content/concepts/dictionary_encoding),
50-character text field:

```sql Modify Table Column Example theme={null}
ALTER TABLE example.employee
ALTER COLUMN first_name VARCHAR(50, DICT) NOT NULL
```

<a id="sql-alter-table-column-drop" />

### Drop Column

An existing column can be removed from a table.

```sql title="Drop Table Column Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
DROP COLUMN <column name>
```

All dependent [views](/content/sql/ddl#sql-create-view),
[materialized views](/content/sql/ddl#sql-create-materialized-view),
[streams](/content/sql/ddl#sql-create-stream), and
[SQL procedures](/content/sql/procedure#sql-procedures) will be dropped.

<Info>
  Any *tables* with [foreign keys](/content/concepts/tables#foreign-key) that
  target the column being dropped must be dropped before it can be dropped.
</Info>

<a id="sql-alter-table-column-index-add" />

### Add Column Index

A [column (attribute) index](/content/concepts/indexes#column-index) can be added to a table
column in order to improve the performance of operations whose expressions
contain relational operators against the column.  See
[Limitations](/content/concepts/indexes#column-index-limitations) for restrictions.

```sql title="Add Table Column Index Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
ADD INDEX (<column name>)
```

For example, to index the `employee` table's `last_name` column:

```sql Add Table Column Index Example theme={null}
ALTER TABLE example.employee
ADD INDEX (last_name)
```

<a id="sql-alter-table-column-index-drop" />

### Drop Column Index

An existing [column (attribute) index](/content/concepts/indexes#column-index) can be
removed from a table.

```sql title="Drop Table Column Index Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
DROP INDEX (<column name>)
```

For example, to drop the index on the `employee` table's `last_name` column:

```sql Drop Table Column Index Example theme={null}
ALTER TABLE example.employee
DROP INDEX (last_name)
```

<a id="sql-alter-table-low-cardinality-index-add" />

### Add Low-Cardinality Index

A [low-cardinality index](/content/concepts/indexes#low-cardinality-index) can be added to a
table column with few distinct values in order to improve the performance of
operations whose expressions contain relational operators against the column.
See [Limitations](/content/concepts/indexes#column-index-limitations) for restrictions.

```sql title="Add Table Low-Cardinality Index Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
ADD LOW CARDINALITY INDEX (<column name>)
```

For example, to index the `employee` table's `dept_id` column:

```sql Add Table Low-Cardinality Index Example theme={null}
ALTER TABLE example.employee
ADD LOW CARDINALITY INDEX (dept_id)
```

<a id="sql-alter-table-low-cardinality-index-drop" />

### Drop Low-Cardinality Index

An existing [low-cardinality index](/content/concepts/indexes#low-cardinality-index) can be
removed from a table.

```sql title="Drop Table Low-Cardinality Index Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
DROP LOW CARDINALITY INDEX (<column name>)
```

For example, to drop the index on the `employee` table's `dept_id` column:

```sql Drop Table Low-Cardinality Index Example theme={null}
ALTER TABLE example.employee
DROP LOW CARDINALITY INDEX (dept_id)
```

<a id="sql-alter-table-chunk-skip-index-add" />

### Add Chunk Skip Index

A [chunk skip index](/content/concepts/indexes#chunk-skip-index) can be added to a table
column in order to improve the performance of operations containing
equality-based filters against the column.  See
[Limitations](/content/concepts/indexes#chunk-skip-index-limitations) for restrictions.

```sql title="Add Table Chunk Skip Index Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
ADD CHUNK [SKIP] INDEX (<column name>)
```

For example, to index the `employee` table's employee ID column:

```sql Add Table Chunk Skip Index Example theme={null}
ALTER TABLE example.employee
ADD CHUNK SKIP INDEX (id)
```

<a id="sql-alter-table-chunk-skip-index-drop" />

### Drop Chunk Skip Index

An existing [chunk skip index](/content/concepts/indexes#chunk-skip-index) can be removed
from a table.

```sql title="Drop Table Chunk Skip Index Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
DROP CHUNK [SKIP] INDEX (<column name>)
```

For example, to drop the chunk skip index on the `employee` table's employee ID column:

```sql Drop Table Chunk Skip Index Example theme={null}
ALTER TABLE example.employee
DROP CHUNK SKIP INDEX (id)
```

<a id="sql-alter-table-geospatial-index-add" />

### Add Geospatial Index

A [geospatial index](/content/concepts/indexes#geospatial-index) can be added to one or more
table columns to improve the performance of geospatial functions applied to
them.

```sql title="Add Table Geospatial Index Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
ADD GEOSPATIAL INDEX (<column name>[,...])
```

For example, to index the `employee` table's work district WKT column:

```sql Add Table WKT Geospatial Index Example theme={null}
ALTER TABLE example.employee
ADD GEOSPATIAL INDEX (work_district)
```

To index the `employee` table's office location coordinate pair columns:

```sql Add Table Coordinate Pair Geospatial Index Example theme={null}
ALTER TABLE example.employee
ADD GEOSPATIAL INDEX (office_longitude, office_latitude)
```

<a id="sql-alter-table-geospatial-index-drop" />

### Drop Geospatial Index

An existing [geospatial index](/content/concepts/indexes#geospatial-index) can be removed
from a table.

```sql title="Drop Table Geospatial Index Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
DROP GEOSPATIAL INDEX (<column name>[,...])
```

For example, to drop the geospatial index on the `employee` table's work
district WKT column:

```sql Drop Table WKT Geospatial Index Example theme={null}
ALTER TABLE example.employee
DROP GEOSPATIAL INDEX (work_district)
```

To drop the geospatial index on the `employee` table's office location
coordinate pair columns:

```sql Drop Table Coordinate Pair Geospatial Index Example theme={null}
ALTER TABLE example.employee
DROP GEOSPATIAL INDEX (office_longitude, office_latitude)
```

<a id="sql-alter-table-cagra-index-add" />

### Add CAGRA Index

A [CAGRA index](/content/concepts/indexes#cagra-index) can be added to a table
column in order to improve the performance of
[vector searches](/content/vector_search) applied to the column.

```sql title="Add Table CAGRA Index Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
ADD CAGRA INDEX (<column name>)
```

For example, to add a CAGRA index on the `employee` table's profile column:

```sql Add Table CAGRA Index Example theme={null}
ALTER TABLE example.employee
ADD CAGRA INDEX (profile)
```

<a id="sql-alter-table-cagra-index-refresh" />

### Refresh CAGRA Index

An existing [CAGRA index](/content/concepts/indexes#cagra-index) can be refreshed.

```sql title="Refresh Table CAGRA Index Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
REFRESH CAGRA INDEX ON (<column name>)
```

For example, to refresh the CAGRA index on the `employee` table's profile column:

```sql Refresh Table CAGRA Index Example theme={null}
ALTER TABLE example.employee
REFRESH CAGRA INDEX ON (profile)
```

<a id="sql-alter-table-cagra-index-drop" />

### Drop CAGRA Index

An existing [CAGRA index](/content/concepts/indexes#cagra-index) can be removed from a
table.

```sql title="Drop Table CAGRA Index Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
DROP CAGRA INDEX (<column name>)
```

For example, to drop the CAGRA index on the `employee` table's profile column:

```sql Drop Table CAGRA Index Example theme={null}
ALTER TABLE example.employee
DROP CAGRA INDEX (profile)
```

<a id="sql-alter-table-hnsw-index-add" />

### Add HNSW Index

An [HNSW index](/content/concepts/indexes#hnsw-index) can be added to a table
column in order to improve the performance of
[vector searches](/content/vector_search) applied to the column.

```sql title="Add Table HNSW Index Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
ADD HNSW INDEX (<column name>)
```

For example, add an HNSW index on the `employee` table's profile column:

```sql Add Table HNSW Index Example theme={null}
ALTER TABLE example.employee
ADD HNSW INDEX (profile)
```

<a id="sql-alter-table-hnsw-index-drop" />

### Drop HNSW Index

An existing [HNSW index](/content/concepts/indexes#hnsw-index) can be removed from a
table.

```sql title="Drop Table HNSW Index Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
DROP HNSW INDEX (<column name>)
```

For example, to drop the HNSW index on the `employee` table's profile column:

```sql Drop Table HNSW Index Example theme={null}
ALTER TABLE example.employee
DROP HNSW INDEX (profile)
```

<a id="sql-alter-table-foreign-key-add" />

### Add Foreign Key

A [foreign key](/content/concepts/tables#foreign-key) can be added to any column or set of
columns with [primary key applicable types](/content/concepts/tables#primary-key-def) in
order to improve the performance of [join](/content/sql/query#sql-join) operations
between the table being altered and the table referenced in the *foreign key*.

```sql title="Add Table Foreign Key Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
ADD FOREIGN KEY (<column name>,...)
    REFERENCES [<foreign table schema name>.]<foreign table name>(<foreign column name>,...) [AS <foreign key name>]
```

For example, to add a foreign key on the `employee` table's department ID
column, linking it to the `department` table's department ID column:

```sql Add Table Foreign Key Example theme={null}
ALTER TABLE example.employee
ADD FOREIGN KEY (dept_id) REFERENCES example.department(id) AS fk_emp_dept
```

### Drop Foreign Key

An existing [foreign key](/content/concepts/tables#foreign-key) can be removed from a table, either
by the name (alias) given to it during creation or by its definition:

```sql title="Drop Table Foreign Key by Name Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
DROP FOREIGN KEY <foreign key name>
```

```sql title="Drop Table Foreign Key by Definition Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
DROP FOREIGN KEY (<column name>,...)
    REFERENCES [<foreign table schema name>.]<foreign table name>(<foreign column name>,...)
```

For example, to drop the *foreign key* on the `employee` table's department ID
column:

```sql Drop Table Foreign Key by Name Example theme={null}
ALTER TABLE example.employee
DROP FOREIGN KEY fk_emp_dept
```

```sql Drop Table Foreign Key by Definition Example theme={null}
ALTER TABLE example.employee
DROP FOREIGN KEY (dept_id) REFERENCES example.department(id)
```

<a id="sql-alter-table-partition-add" />

### Add Partition

A *partition* can be added to a [range-partitioned](/content/concepts/tables#partitioning-by-range)
or [list-partitioned](/content/concepts/tables#partitioning-by-list) table.

<Warning>
  Defining (adding) partitions after data has been loaded will
  result in a performance penalty as the database moves existing records
  targeted for the new partition from the *default partition* into it.
</Warning>

#### Range Partition

The new *partition* can be given a minimum bound (inclusive) and a maximum bound
(exclusive).  If the new *partition* would come before an existing *partition*,
omitting the maximum bound would cause the new *partition* to take on the
nearest following existing *partition's* minimum bound as its maximum bound.
If the new *partition* would come after an existing *partition*, omitting the
minimum bound would cause the new *partition* to take on the nearest preceding
*partition's* maximum bound as its minimum bound.  If no *partitions* are
present in the table, the new *partition* will have to declare both a minimum
and maximum bound.

```sql title="Add Table Range Partition Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
ADD PARTITION <partition name> [ MIN ( <least value> ) ] [ MAX ( <greatest value> ) ]
```

For example, to add a *partition* to the `customer_order_range_by_year` table,
containing all records with a *partition key* less than `2020` and greater
than or equal to the maximum bound of the nearest preceding *partition*:

```sql Add Table Range Partition Example theme={null}
ALTER TABLE example.customer_order_range_partition_by_year
ADD PARTITION order_2020 MAX(2021)
```

#### List Partition

The new *partition* can be given a list of values to match against the
*partition key* values of incoming records.

```sql title="Add Table List Partition Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
ADD PARTITION <partition name> VALUES ( <value lists> )
```

For example, to add a *partition* to the
`customer_order_manual_list_partition_by_year` table, containing all records
from *2020*:

```sql Add Table List Partition (Year) Example theme={null}
ALTER TABLE example.customer_order_manual_list_partition_by_year
ADD PARTITION order_2020 VALUES (2020)
```

For example, to add a *partition* to the
`customer_order_manual_list_partition_by_year_and_month` table, containing all
records from *February 2020* & *April 2020*:

```sql Add Table List Partition (Month) Example theme={null}
ALTER TABLE example.customer_order_manual_list_partition_by_year_and_month
ADD PARTITION order_2020_0204 VALUES ((2020, 2), (2020, 4))
```

<a id="sql-alter-table-partition-remove" />

### Remove Partition

An existing *partition* can be removed from a
[range-partitioned](/content/concepts/tables#partitioning-by-range) or
[list-partitioned](/content/concepts/tables#partitioning-by-list) table, sending all data contained
within that *partition* back to the *default partition*.

```sql title="Remove Table Partition Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
REMOVE PARTITION <partition name>
```

For example, to remove a *partition* named `order_2017` from the
`customer_order_range_by_year` table:

```sql Remove Table Partition Example theme={null}
ALTER TABLE example.customer_order_range_partition_by_year
REMOVE PARTITION order_2017
```

<a id="sql-alter-table-partition-drop" />

### Delete Partition

An existing *partition* can be dropped from a
[range-partitioned](/content/concepts/tables#partitioning-by-range) or
[list-partitioned](/content/concepts/tables#partitioning-by-list) table, deleting all data
contained within it.

```sql title="Delete Table Partition Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
DELETE PARTITION <partition name>
```

For example, to drop a *partition* named `order_2014_2016` from the
`customer_order_range_by_year` table, deleting all data within that
*partition*:

```sql Delete Table Partition Example theme={null}
ALTER TABLE example.customer_order_range_partition_by_year
DELETE PARTITION order_2014_2016
```

<a id="sql-alter-table-set-tier-strategy" />

### Set Tier Strategy

A table's [eviction priorities](/content/rm/concepts#rm-concepts-eviction-priority) can be
adjusted by setting its [tier strategy](/content/rm/concepts#rm-concepts-tier-strategy).

```sql title="Set Table Tier Strategy Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
SET TIER STRATEGY (<tier strategy>)
```

For example, to set the `customer_order` table's *tier strategy*, to one with
a below-average *eviction priority* in the
[RAM Tier](/content/rm/concepts#rm-concepts-tiers-ram):

```sql Set Table Tier Strategy Example theme={null}
ALTER TABLE example.customer_order
SET TIER STRATEGY
(
    ( ( VRAM 1, RAM 3, PERSIST 5 ) )
)
```

The *tier strategy* can also be reset to the
[system default strategy](/content/rm/configuration#rm-config-tier-strategy-default).

```sql title="Reset Table Tier Strategy Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
RESET TIER STRATEGY
```

For example, to reset the `customer_order` table's *tier strategy*:

```sql Reset Table Tier Strategy Example theme={null}
ALTER TABLE example.customer_order
RESET TIER STRATEGY
```

<a id="sql-alter-table-manage-sub" />

### Manage Subscription

Any *table* that is subscribed to a streaming
[external data source](/content/sql/ddl#sql-create-data-source) can have that
subscription paused, resumed, canceled, or dropped.

```sql title="Manage External Table Subscription Syntax" theme={null}
ALTER TABLE [<schema name>.]<table name>
<PAUSE | RESUME | CANCEL | DROP> SUBSCRIPTION <data source name>
```

<Info>
  Once unsubscribed, there is no way to re-subscribe the table to the
  *data source* via `ALTER TABLE`.  An *external table* will need to be
  re-created, while a table whose subscription was initiated through the
  [LOAD INTO](/content/sql/load#sql-load-file-server) command can have that command
  re-executed.
</Info>

For example, to manage a subscription on the `ext_product` *external table*
through the `product_ds` *data source*:

<CodeGroup>
  ```sql Pause Subscription theme={null}
  ALTER TABLE example.ext_product
  PAUSE SUBSCRIPTION example.product_ds
  ```

  ```sql Resume Subscription theme={null}
  ALTER TABLE example.ext_product
  RESUME SUBSCRIPTION example.product_ds
  ```

  ```sql Cancel Subscription theme={null}
  ALTER TABLE example.ext_product
  CANCEL SUBSCRIPTION example.product_ds
  ```

  ```sql Drop Subscription theme={null}
  ALTER TABLE example.ext_product
  DROP SUBSCRIPTION example.product_ds
  ```
</CodeGroup>

<a id="sql-refresh-table" />

## REFRESH EXTERNAL TABLE

Refreshes the data within a *materialized external table* that is not
subscription-based.

```sql title="REFRESH EXTERNAL TABLE Syntax" theme={null}
REFRESH [EXTERNAL] TABLE [<schema name>.]<table name>
```

<Note>
  [Data source connect](/content/sql/security#sql-security-priv-mgmt-ds-grant)
  privilege is required to refresh an *external table* that uses a
  [data source](/content/sql/ddl#sql-create-data-source).
</Note>

<a id="sql-repair-table" />

## REPAIR TABLE

Repairs one or more corrupted tables.  Tables are specified as a comma-separated
list of table names.

```sql title="REPAIR TABLE Syntax" theme={null}
REPAIR TABLE[S] [<schema name>.]<table name>[,...]
WITH OPTIONS (REPAIR_POLICY = '<repair type>')
```

### Parameters

<AccordionGroup>
  <Accordion title="<schema name>" id="<schema-name>-7" defaultOpen>
    Name of the *schema* containing the table to repair
  </Accordion>

  <Accordion title="<view name>" id="<view-name>" defaultOpen>
    Name of the *table* to repair
  </Accordion>

  <Accordion title="REPAIR_POLICY" id="repair_policy" defaultOpen>
    Specifies the type of *table* repair to perform.  The following are available:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Type</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>delete\_chunks</code></td>
            <td>Deletes any corrupted chunks</td>
          </tr>

          <tr>
            <td><code>shrink\_columns</code></td>
            <td>Shrinks corrupted chunks to the shortest column</td>
          </tr>

          <tr>
            <td><code>replay\_wal</code></td>
            <td>Manually invokes WAL replay on the *table*</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>
</AccordionGroup>

### Examples

To manually replay the WAL on two tables:

```sql REPAIR TABLE Example theme={null}
REPAIR TABLES example.rt_product, example.rt_order
WITH OPTIONS (REPAIR_POLICY = 'replay_wal')
```

<a id="sql-truncate-table" />

## TRUNCATE TABLE

Deletes all the records from a table.

```sql title="TRUNCATE TABLE Syntax" theme={null}
TRUNCATE TABLE [<schema name>.]<table name>
```

<a id="sql-drop-table" />

## DROP TABLE

Removes an existing [table](/content/sql/ddl#sql-create-table).  All dependent
[views](/content/sql/ddl#sql-create-view),
[materialized views](/content/sql/ddl#sql-create-materialized-view),
[streams](/content/sql/ddl#sql-create-stream), and
[SQL procedures](/content/sql/procedure#sql-procedures) will be dropped.

```sql title="DROP TABLE Syntax" theme={null}
DROP TABLE [IF EXISTS] [<schema name>.]<table name>
```

<Info>
  Any *tables* with [foreign keys](/content/concepts/tables#foreign-key) that
  target a given *table* must be dropped before it can be dropped.
</Info>

### Parameters

<AccordionGroup>
  <Accordion title="IF EXISTS" id="if-exists-2" defaultOpen>
    Optional error-suppression clause; if specified, no error will be returned if the given
    *table* does not exist
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-8" defaultOpen>
    Name of the *schema* containing the *table* to remove
  </Accordion>

  <Accordion title="<table name>" id="<table-name>-3" defaultOpen>
    Name of the *table* to remove
  </Accordion>
</AccordionGroup>

<a id="sql-show-table" />

## SHOW TABLE

Outputs the DDL statement required to reconstruct the given *table*.

```sql title="SHOW TABLE Syntax" theme={null}
SHOW [[CREATE] TABLE] [<schema name>.]<table name>
```

<Info>
  The response to `SHOW TABLE` is a single-record result set
  with the DDL statement as the value in the `DDL` column, shown below with
  the column separators returned by <Badge color="blue-destructive">kisql</Badge>.
</Info>

### Parameters

<AccordionGroup>
  <Accordion title="CREATE" id="create-2" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="TABLE" id="table" defaultOpen>
    Optional clause to avoid ambiguity:

    * if given, and a *view* with the given name exists instead, the command will return an error
    * if omitted, and a *view* with the given name exists instead, the command will be interpreted as
      a `SHOW VIEW` statement
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-9" defaultOpen>
    Name of the *schema* containing the *table* to show
  </Accordion>

  <Accordion title="<table name>" id="<table-name>-4" defaultOpen>
    Name of the *table* whose DDL will be output
  </Accordion>
</AccordionGroup>

### Examples

To output the DDL for the example table created in the
[CREATE TABLE](/content/sql/ddl#sql-create-table) section:

```sql SHOW TABLE Example theme={null}
SHOW CREATE TABLE example.various_types
```

```sql SHOW TABLE Output theme={null}
| CREATE TABLE "example"."various_types"
(
    "i" INTEGER (primary_key) NOT NULL COMMENT 'non-nullable integer, part of primary key (defined at end)',
    "bi" BIGINT (primary_key, shard_key) NOT NULL COMMENT 'long, part of primary key, shard key, foreign key source (defined at end)',
    "b" BOOLEAN COMMENT '0s and 1s only',
    "ub" UNSIGNED BIGINT COMMENT 'native unsigned long',
    "r" REAL COMMENT 'native float',
    "d" DOUBLE COMMENT 'native double',
    "s" VARCHAR (text_search) COMMENT 'string, searchable, only limited in size by system-configured value',
    "c" VARCHAR (32, dict) COMMENT 'char32 using dictionary-encoding of values',
    "p" VARCHAR (256, text_search) COMMENT 'char256, searchable',
    "ip" IPV4 COMMENT 'IP address',
    "ui" UUID DEFAULT NEW_UUID() COMMENT 'UUID',
    "ts" TIMESTAMP COMMENT 'timestamp',
    "td" DATE COMMENT 'simple date',
    "tt" TIME COMMENT 'simple time',
    "dt" DATETIME DEFAULT NOW() COMMENT 'date/time',
    "dc" DECIMAL (28, 0) COMMENT 'integer of up to 27 digits',
    "dc8" DECIMAL (18, 4) COMMENT '8-byte decimal',
    "dc12" DECIMAL (27, 18) COMMENT '12-byte decimal',
    "n" DECIMAL (18, 4) COMMENT 'alias for DECIMAL(18, 4)',
    "byt" BLOB COMMENT 'BLOB',
    "w" GEOMETRY COMMENT 'geospatial column for WKT string data',
    "j" JSON COMMENT 'JSON string',
    "v" VECTOR (10) COMMENT 'vector column holding 10 floating point values',
    "ai" INTEGER[3] COMMENT 'array column holding 3 integer values',
    FOREIGN KEY ("bi") REFERENCES "example"."lookup" ("id") AS "fk"
)
TIER STRATEGY (
    ( ( VRAM 1, RAM 5, DISK0 5, PERSIST 5 ) )
)
ATTRIBUTE INDEX ("ip")
ATTRIBUTE INDEX ("ts"); |
```

## DESCRIBE TABLE

Lists the columns and column types & properties for a given *table*.

```sql title="DESCRIBE TABLE Syntax" theme={null}
DESC[RIBE] [TABLE] [<schema name>.]<table name>
```

### Parameters

<AccordionGroup>
  <Accordion title="TABLE" id="table-2" defaultOpen>
    Optional clause to avoid ambiguity:

    * if given, and a *view* with the given name exists instead, the command will return an error
    * if omitted, and a *view* with the given name exists instead, the command will be interpreted as
      a `DESCRIBE VIEW` statement
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-10" defaultOpen>
    Name of the *schema* containing the *table* to describe
  </Accordion>

  <Accordion title="<table name>" id="<table-name>-5" defaultOpen>
    Name of the *table* whose configuration will be output
  </Accordion>
</AccordionGroup>

### Examples

To describe the example table created in the [CREATE TABLE](/content/sql/ddl#sql-create-table) section:

```sql DESCRIBE TABLE Example theme={null}
DESC example.various_types
```

```sql DESCRIBE TABLE Output theme={null}
+-----------+--------+------------+-----------------------------------+
| Col_num   | Name   | Null?      | Type                              |
+-----------+--------+------------+-----------------------------------+
| 0         | i      | NOT NULL   | INTEGER (primary_key)             |
| 1         | bi     | NOT NULL   | BIGINT (primary_key, shard_key)   |
| 2         | b      |            | BOOLEAN                           |
| 3         | ub     |            | UNSIGNED BIGINT                   |
| 4         | r      |            | REAL                              |
| 5         | d      |            | DOUBLE                            |
| 6         | s      |            | VARCHAR (text_search)             |
| 7         | c      |            | VARCHAR (32, dict)                |
| 8         | p      |            | VARCHAR (256, text_search)        |
| 9         | ip     |            | IPV4                              |
| 10        | ui     |            | UUID (init_with_uuid)             |
| 11        | ts     |            | TIMESTAMP                         |
| 12        | td     |            | DATE                              |
| 13        | tt     |            | TIME                              |
| 14        | dt     |            | DATETIME (init_with_now)          |
| 15        | dc     |            | DECIMAL (28, 0)                   |
| 16        | dc8    |            | DECIMAL (18, 4)                   |
| 17        | dc12   |            | DECIMAL (27, 18)                  |
| 18        | n      |            | DECIMAL (18, 4)                   |
| 19        | byt    |            | BLOB                              |
| 20        | w      |            | GEOMETRY                          |
| 21        | j      |            | JSON                              |
| 22        | v      |            | VECTOR (10)                       |
| 23        | ai     |            | INTEGER[3]                        |
+-----------+--------+------------+-----------------------------------+
```

<a id="sql-create-view" />

## CREATE VIEW

Creates a new *virtual table* from the given query.

```sql title="CREATE VIEW Syntax" theme={null}
CREATE [OR REPLACE] VIEW [<schema name>.]<view name> AS
<select statement>
```

When any of the source *tables* of a *view* is altered or dropped, the *view*
will also be dropped.

<Warning>
  A `CREATE OR REPLACE` issues an implicit drop, so *replacing* an
  input *table* will have the same effect on the *view* as dropping it.
</Warning>

### Parameters

<AccordionGroup>
  <Accordion title="OR REPLACE" id="or-replace-3" defaultOpen>
    Any existing *table*/*view* with the same name will be dropped before creating this *view*
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-11" defaultOpen>
    Name of the *schema* that will contain the created *view*; if no *schema* is specified, the
    *view* will be created in the user's [default schema](/content/concepts/schemas#schema-default)
  </Accordion>

  <Accordion title="<view name>" id="<view-name>-2" defaultOpen>
    Name of the *view* to create; must adhere to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria)
  </Accordion>

  <Accordion title="<select statement>" id="<select-statement>" defaultOpen>
    The query that will define both the structure and content of the created *view*
  </Accordion>
</AccordionGroup>

### Examples

To create a view that is a copy of an existing table, failing if a
table or view with the same name as the target view already exists:

```sql CREATE VIEW Example theme={null}
CREATE VIEW example.view_of_table AS
(
    SELECT *
    FROM example.table_to_view
)
```

<a id="sql-create-materialized-view" />

## CREATE MATERIALIZED VIEW

Specifying `MATERIALIZED` in a [CREATE VIEW](/content/sql/ddl#sql-create-view) statement
will make the view a [materialized view](/content/concepts/materialized_views).

```sql title="CREATE MATERIALIZED VIEW Syntax" theme={null}
CREATE [OR REPLACE] [TEMP] MATERIALIZED VIEW [<schema name>.]<view name>
[
    REFRESH
    <
        OFF |
        ON CHANGE |
        ON QUERY |
        EVERY <number> <SECOND[S] | MINUTE[S] | HOUR[S] | DAY[S]>
            [STARTING AT '<YYYY-MM-DD [HH:MM[:SS]]>']
            [STOP AFTER < '<YYYY-MM-DD [HH:MM[:SS]]>' | <number> <SECOND[S] | MINUTE[S] | HOUR[S] | DAY[S]> >]
    >
]
AS
<select statement>
[WITH OPTIONS (<materialized view property name> = '<materialized view property value>'[,...])]
[<table property clause>]
```

The intermediary results of *materialized views* are cached to improve the
performance of queries against them.  This means that, unlike typical *views*,
*materialized views* are not lightweight database entities, but rather consume
memory and processing time proportional to the size of the source data and
complexity of the query.

When any of the source *tables* of a *materialized view* is altered or dropped,
the *materialized view* will also be dropped.

<Warning>
  A `CREATE OR REPLACE` issues an implicit drop, so *replacing* an
  input *table* will have the same effect on the *materialized view* as
  dropping it.
</Warning>

While [primary keys](/content/concepts/tables#primary-key) &
[foreign keys](/content/concepts/tables#foreign-key) are not transferred to the new
*materialized view*, [shard keys](/content/concepts/tables#shard-key) will be, if the
column(s) composing them are part of the `SELECT` list.  A new *shard key* can
be specified for the *materialized view* by using the
`KI_SHARD_KEY(<column list>)` pseudo-function in the `SELECT` list.

### Parameters

<AccordionGroup>
  <Accordion title="OR REPLACE" id="or-replace-4" defaultOpen>
    Any existing *table*/*view* with the same name will be dropped before creating this
    *materialized view*
  </Accordion>

  <Accordion title="TEMP" id="temp-3" defaultOpen>
    The *materialized view* will be a [memory-only table](/content/concepts/tables_memory_only);
    which, among other things, means it will not be persisted (if the database is restarted, the
    *materialized view* will be removed), but it will have increased ingest performance
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-12" defaultOpen>
    Name of the *schema* that will contain the created *materialized view*; if no *schema* is
    specified, the *materialized view* will be created in the user's
    [default schema](/content/concepts/schemas#schema-default)
  </Accordion>

  <Accordion title="<view name>" id="<view-name>-3" defaultOpen>
    Name of the *materialized view* to create; must adhere to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria)
  </Accordion>

  <Accordion title="REFRESH" id="refresh" defaultOpen>
    Specifies the data refresh scheme for the *materialized view*.   The following schemes are
    available:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Constant</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>OFF</code></td>
            <td>*(the default)* Will prevent the *materialized view* from being automatically refreshed, but will still allow [manual refreshes](/content/sql/ddl#sql-refresh-view) of the data to be requested</td>
          </tr>

          <tr>
            <td><code>ON CHANGE</code></td>
            <td>Will cause the *materialized view* to be updated any time a record is added, modified, or deleted from the subtending *tables* in its query</td>
          </tr>

          <tr>
            <td><code>ON QUERY</code></td>
            <td>Will cause the *materialized view* to be updated any time it is queried</td>
          </tr>

          <tr>
            <td><code>EVERY</code></td>
            <td>Allows specification of an interval in seconds, minutes, hours, or days, at which the *materialized view* should be refreshed.  By default, the first refresh interval will be one interval's worth of time from the point at which the *materialized view* creation was requested.  This can be modified with the following options: <ul><li><code>STARTING AT</code>:  specify a date or timestamp at which refresh cycles should begin</li><li><code>STOP AFTER</code>:  specify a date, timestamp, or time interval after which refresh cycles should end</li></ul></td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="<select statement>" id="<select-statement>-2" defaultOpen>
    The query that will define both the structure and content of the created *materialized view*
  </Accordion>

  <Accordion title="WITH OPTIONS" id="with-options-2" defaultOpen>
    Optional indicator that a comma-delimited list of connection option/value assignments will
    follow.  The following options are available:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Option</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>EXECUTE AS</code></td>
            <td>Executes *materialized view* refreshes as the given user with that user's privileges, when <code>EVERY ...</code> is specified as the <code>REFRESH</code> method. <Note>If this user doesn't exist at the time of a refresh, the refresh will be executed as the creating user, and, failing that, the system administration user.</Note></td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="<table property clause>" id="<table-property-clause>-3" defaultOpen>
    Optional clause, assigning table properties, from a subset of those available, to the
    *materialized view*
  </Accordion>
</AccordionGroup>

<a id="sql-create-materialized-view-prop" />

### Table Property Clause

A subset of *table* properties can be applied to the *materialized view* at
creation time.

The supported *Table Property Clause* syntax & features are the same as those in
the [CREATE TABLE Table Property Clause](/content/sql/ddl#sql-create-table-prop).

<a id="sql-create-materialized-view-delta" />

### Changes-Only Views via Delta Tables

A *materialized view* can be configured to only show the changes in the query
result since its last refresh.  This applies strictly for inserts; updates and
deletes will not be reflected in the view's data.

Using a *materialized view* to only show deltas in the result data can be
achieved using the `KI_HINT_DELTA_TABLE` scoped hint.  This hint should be
placed immediately after the table name (and before any table alias) of each
source table in the query that should be treated as a *delta table*--a table
which will contribute to the result set only those records added since the last
time the *materialized view* referencing it was refreshed.

The marked *delta table* must be a regular table--it cannot be any of the
following:

* [external table](/content/sql/ddl#sql-create-ext-table)
* [filter view](/content/concepts/filtered_views)
* [join view](/content/concepts/joins)
* [logical view](/content/sql/ddl#sql-create-view)
* [materialized view](/content/sql/ddl#sql-create-materialized-view)

For instance, a *changes-only materialized view* `weather_zone` can be created
with its `weather` source table marked as a *delta table* in order to only
show new weather events since the last refresh of `weather_zone`:

```sql Create Changes-Only Materialized View theme={null}
CREATE MATERIALIZED VIEW example.weather_zone AS
SELECT w.name AS event_name, w.type AS event_type, gz.name AS zone
FROM example.weather /*+ KI_HINT_DELTA_TABLE */ w
JOIN example.geo_zone gz ON STXY_INTERSECTS(lon, lat, zone)
```

After an initial round of data is inserted, a query on the *materialized view*
might return this:

```sql Create Changes-Only Materialized View Output, Round 1 theme={null}
+--------------+--------------+-------------+
| event_name   | event_type   | zone        |
+--------------+--------------+-------------+
| Anna         | Hurricane    | Northeast   |
| Bob          | Monsoon      | Northwest   |
| Civic        | High Winds   | Southwest   |
+--------------+--------------+-------------+
```

After another round of data is inserted, a query on the *materialized view*
might return this:

```sql Create Changes-Only Materialized View Output, Round 2 theme={null}
+--------------+--------------+-------------+
| event_name   | event_type   | zone        |
+--------------+--------------+-------------+
| Dened        | Hurricane    | Southeast   |
+--------------+--------------+-------------+
```

### Examples

To create a *materialized view* with columns `a`, `b`, `c`, & `d` and a
new *shard key* on columns `a` & `b`, that refreshes once per half hour,
replacing a *view* with the same name as the target *view*, if it exists:

```sql CREATE MATERIALIZED VIEW Example theme={null}
CREATE OR REPLACE MATERIALIZED VIEW example.materialized_view_of_table
REFRESH EVERY .5 HOURS AS
(
    SELECT a, b, c, d, KI_SHARD_KEY(a, b)
    FROM example.table_to_view
)
```

To create a *materialized view* with all columns of a table, refreshing once per
minute from the beginning of *2025* through to the end of that year using the
permissions of user *mv\_user* to perform the refreshes:

```sql CREATE MATERIALIZED VIEW Start/Stop Example theme={null}
CREATE MATERIALIZED VIEW example.materialized_view_of_table
REFRESH EVERY 1 MINUTE
STARTING AT '2025-01-01 00:00:00'
STOP AFTER 365 DAYS
AS
(
    SELECT *
    FROM example.table_to_view
)
WITH OPTIONS (EXECUTE AS = 'mv_user')
```

To create a *materialized view* that shows only weather events from a streamed
`weather` table and their locations from a static `geo_zone` table that have
occurred since the last time the materialized view `weather_zone` joining the
two data sets was refreshed:

```sql CREATE MATERIALIZED VIEW Changes-Only Example theme={null}
CREATE MATERIALIZED VIEW example.weather_zone AS
SELECT w.name AS event_name, w.type AS event_type, gz.name AS zone
FROM example.weather /*+ KI_HINT_DELTA_TABLE */ w
JOIN example.geo_zone gz ON STXY_INTERSECTS(lon, lat, zone)
```

<a id="sql-alter-view" />

## ALTER VIEW

Alters the configuration of a [view](/content/sql/ddl#sql-create-view).

The following facet of a *view* can be altered:

* [Schema](/content/sql/ddl#sql-alter-view-move)

<a id="sql-alter-view-move" />

### Move View

A *view* can be moved from one schema to another.

```sql title="Move View Syntax" theme={null}
ALTER VIEW [<schema name>.]<view name>
< MOVE TO | SET SCHEMA > <new schema name>
```

All dependent [views](/content/sql/ddl#sql-create-view),
[materialized views](/content/sql/ddl#sql-create-materialized-view),
[streams](/content/sql/ddl#sql-create-stream), and
[SQL procedures](/content/sql/procedure#sql-procedures) will be dropped.

For example, to move the `sales_2017` *view* from the `example_olap`
*schema* to the `example_archive` *schema*:

```sql Move View Example theme={null}
ALTER VIEW example_olap.sales_2017
MOVE TO example_archive;
```

<a id="sql-alter-materialized-view" />

## ALTER MATERIALIZED VIEW

Alters the configuration of a
[materialized view](/content/sql/ddl#sql-create-materialized-view).

Any of the following facets of a *materialized view* can be altered:

* [Schema](/content/sql/ddl#sql-alter-mview-move)
* [Access Mode](/content/sql/ddl#sql-alter-mview-set-access-mode)
* [Execution User](/content/sql/ddl#sql-alter-mview-set-execute-as)
* [Refresh Mode](/content/sql/ddl#sql-alter-mview-set-refresh-mode)
* [TTL](/content/sql/ddl#sql-alter-mview-set-ttl)

<a id="sql-alter-mview-move" />

### Move View

A *materialized view* can be moved from one schema to another.

```sql title="Move View Syntax" theme={null}
ALTER MATERIALIZED VIEW [<schema name>.]<view name>
< MOVE TO | SET SCHEMA > <new schema name>
```

All dependent [views](/content/sql/ddl#sql-create-view),
[materialized views](/content/sql/ddl#sql-create-materialized-view),
[streams](/content/sql/ddl#sql-create-stream), and
[SQL procedures](/content/sql/procedure#sql-procedures) will be dropped.

For example, to move the `sales_current` *view* from the `example_olap`
*schema* to the `example_archive` *schema*:

```sql Move Materialized View Example theme={null}
ALTER MATERIALIZED VIEW example_olap.sales_current
MOVE TO example_archive
```

<a id="sql-alter-mview-set-access-mode" />

### Set Access Mode

A *materialized view* can have its global accessibility modified for all users
in the system, independently from and further restricting any role-based access
controls in place.

```sql title="Set Materialized View Access Mode Syntax" theme={null}
ALTER MATERIALIZED VIEW [<schema name>.]<view name>
SET ACCESS MODE < NO_ACCESS | READ_ONLY | WRITE_ONLY | READ_WRITE >
```

<Info>
  Changing the access mode cannot *widen* access for users not already
  granted access; it can only *narrow* access for those who already have
  access.  This setting will also trump administrative access to a
  *materialized view*.
</Info>

<a id="sql-alter-mview-set-execute-as" />

### Set Execution User

A *materialized view* can have its execution user for periodic refreshes
(`REFRESH` is set to `EVERY ...`) changed to the given user.

```sql title="Set Materialized View Execution User Syntax" theme={null}
ALTER MATERIALIZED VIEW [<schema name>.]<view name>
SET EXECUTE AS '<user name>'
```

<Info>
  If this user doesn't exist at the time of a refresh, the refresh will
  be executed as the creating user, and, failing that, the system
  administration user.
</Info>

<a id="sql-alter-mview-set-refresh-mode" />

### Set Refresh Mode

The refresh mode of a *materialized view* can be modified.

```sql title="Set Materialized View Refresh Mode Syntax" theme={null}
ALTER MATERIALIZED VIEW [<schema name>.]<view name>
SET REFRESH
<
    OFF |
    ON CHANGE |
    ON QUERY |
    EVERY <number> <SECOND[S] | MINUTE[S] | HOUR[S] | DAY[S]>
        [STARTING AT '<YYYY-MM-DD [HH:MM[:SS]]>']
        [STOP AFTER < '<YYYY-MM-DD [HH:MM[:SS]]>' | <number> <SECOND[S] | MINUTE[S] | HOUR[S] | DAY[S]> >]
>
```

The available refresh modes are:

| Constant    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `OFF`       | Will prevent the *materialized view* from being automatically refreshed, but will still allow [manual refreshes](/content/sql/ddl#sql-refresh-view) of the data to be requested                                                                                                                                                                                                                                                                                                                                                                      |
| `ON CHANGE` | Will cause the *materialized view* to be updated any time a record is added, modified, or deleted from the subtending *tables* in its query                                                                                                                                                                                                                                                                                                                                                                                                          |
| `ON QUERY`  | Will cause the *materialized view* to be updated any time it is queried                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `EVERY`     | Allows specification of an interval in seconds, minutes, hours, or days, at which the *materialized view* should be refreshed.  By default, the first refresh interval will be one interval's worth of time from the point at which the *materialized view* alteration was requested.  This can be modified with the following options: <br /> <br /> \* `STARTING AT`:  specify a date or timestamp at which refresh cycles should begin <br /> \* `STOP AFTER`:  specify a date, timestamp, or time interval after which refresh cycles should end |

For example, to alter the current sales *materialized view* to refresh every 6
hours:

```sql Set Materialized View Refresh Mode by Hour Example theme={null}
ALTER MATERIALIZED VIEW example_olap.sales_current
SET REFRESH EVERY 6 HOURS
```

```sql Set Materialized View Refresh Mode with Start/Stop Example theme={null}
ALTER MATERIALIZED VIEW example_olap.sales_current
SET REFRESH EVERY 1 MINUTE
    STARTING AT '2026-01-01 00:00:00'
    STOP AFTER 31 DAYS
```

<a id="sql-alter-mview-set-ttl" />

### Set TTL

A *materialized view's* [time-to-live (TTL)](/content/concepts/ttl) can be
altered.

```sql title="Set Materialized View TTL Syntax" theme={null}
ALTER MATERIALIZED VIEW [<schema name>.]<view name>
SET TTL <new ttl>
```

<a id="sql-refresh-view" />

## REFRESH VIEW

Refreshes the data within a
[materialized view](/content/sql/ddl#sql-create-materialized-view).  This will also
re-validate invalidated *materialized views*, making them accessible once again
if their query criteria is met (it can be successfully run again).

```sql title="Refresh Materialized View Syntax" theme={null}
REFRESH MATERIALIZED VIEW [<schema name>.]<view name>
```

<a id="sql-drop-view" />

## DROP VIEW

Removes an existing [view](/content/sql/ddl#sql-create-view) or
[materialized view](/content/sql/ddl#sql-create-materialized-view).  All dependent
[views](/content/sql/ddl#sql-create-view),
[materialized views](/content/sql/ddl#sql-create-materialized-view),
[streams](/content/sql/ddl#sql-create-stream), and
[SQL procedures](/content/sql/procedure#sql-procedures) will be dropped.

```sql title="DROP VIEW Syntax" theme={null}
DROP [MATERIALIZED] VIEW [IF EXISTS] [<schema name>.]<view name>
```

### Parameters

<AccordionGroup>
  <Accordion title="MATERIALIZED" id="materialized-2" defaultOpen>
    Optional keyword for clarity; has no impact on functionality
  </Accordion>

  <Accordion title="IF EXISTS" id="if-exists-3" defaultOpen>
    Optional error-suppression clause; if specified, no error will be returned if the given
    *view* does not exist
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-13" defaultOpen>
    Name of the *schema* containing the *view* to remove
  </Accordion>

  <Accordion title="<view name>" id="<view-name>-4" defaultOpen>
    Name of the *view* to remove
  </Accordion>
</AccordionGroup>

## SHOW VIEW

Outputs the DDL statement required to reconstruct the given
[view](/content/sql/ddl#sql-create-view) or
[materialized view](/content/sql/ddl#sql-create-materialized-view).

```sql title="SHOW VIEW Syntax" theme={null}
SHOW [[CREATE] VIEW] [<schema name>.]<view name> [WITH OPTIONS (<options>)]
```

<Tip>
  To show the *view*, along with all its base table dependencies (and its
  dependencies' dependencies, etc.), use:

  ```
  WITH OPTIONS ('dependencies' = 'true')
  ```

  Output will be in dependency-order, with dependencies listed before *views*
  that depend on them.  This allows the output to be run as a sequence of SQL
  commands to recreate the final *view* with all of its dependencies.
</Tip>

<Info>
  The response to `SHOW VIEW` is a single-record result set
  with the DDL statement as the value in the `DDL` column, shown below with
  the column separators returned by <Badge color="blue-destructive">kisql</Badge>.
</Info>

### Parameters

<AccordionGroup>
  <Accordion title="CREATE" id="create-3" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="VIEW" id="view" defaultOpen>
    Optional clause to avoid ambiguity:

    * if given, and a *table* with the given name exists instead, the command will return an error
    * if omitted, and a *table* with the given name exists instead, the command will be interpreted
      as a `SHOW TABLE` statement
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-14" defaultOpen>
    Name of the *schema* containing the *view* to show
  </Accordion>

  <Accordion title="<view name>" id="<view-name>-5" defaultOpen>
    Name of the *view* whose DDL will be output
  </Accordion>

  <Accordion title="WITH OPTIONS" id="with-options-3" defaultOpen>
    Optional indicator that a comma-delimited list of connection option/value assignments will
    follow.

    All valid options from [Show Table](/content/api/rest/show_table_rest)
    can be used here.
  </Accordion>
</AccordionGroup>

### Examples

To output the DDL for the example *view* created in the
[CREATE VIEW](/content/sql/ddl#sql-create-view) section:

```sql SHOW VIEW Example theme={null}
SHOW VIEW example.view_of_table
```

## DESCRIBE VIEW

Lists the columns and column types & properties for a given
[view](/content/sql/ddl#sql-create-view) or
[materialized view](/content/sql/ddl#sql-create-materialized-view).

```sql title="DESCRIBE VIEW Syntax" theme={null}
DESC[RIBE] [VIEW] [<schema name>.]<view name>
```

### Parameters

<AccordionGroup>
  <Accordion title="VIEW" id="view-2" defaultOpen>
    Optional clause to avoid ambiguity:

    * if given, and a *table* with the given name exists instead, the command will return an error
    * if omitted, and a *table* with the given name exists instead, the command will be interpreted
      as a `DESCRIBE TABLE` statement
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-15" defaultOpen>
    Name of the *schema* containing the *view* to describe
  </Accordion>

  <Accordion title="<view name>" id="<view-name>-6" defaultOpen>
    Name of the *view* whose configuration will be output
  </Accordion>
</AccordionGroup>

### Examples

To describe the example *view* created in the
[CREATE VIEW](/content/sql/ddl#sql-create-view) section:

```sql DESCRIBE VIEW Example theme={null}
DESC VIEW example.view_of_table
```

<a id="sql-create-credential" />

## CREATE CREDENTIAL

Creates a new [credential](/content/concepts/credentials), which is a
record that contains authentication information required to connect to a
resource outside the database.  Any user may create a *credential* for their own
use.

```sql title="CREATE CREDENTIAL Syntax" theme={null}
CREATE [OR REPLACE] CREDENTIAL [<schema name>.]<credential name>
TYPE = '<type>',
IDENTITY = '<username>',
SECRET = '<password>'
[WITH OPTIONS ('<option name>' = '<option value>'[,...])]
```

The following can make use of *credentials*:

* [Data sources](/content/sql/ddl#sql-create-data-source)
* [Data sinks](/content/sql/ddl#sql-create-data-sink)
* [ML container registries](/content/sql/ml#sql-ml-create-cr)

The following services are supported:

* Azure *(Microsoft blob storage)*

* GCS *(Google Cloud Storage)*

* HDFS *(Apache Hadoop Distributed File System)*

* JDBC *(Java Database Connectivity, using a user-supplied driver or one of the*
  *drivers on the [supported list](/content/concepts/jdbc_drivers))*

* Kafka *(streaming feed)*

  * *Apache*
  * *Confluent*

* Remote Repositories

  * *Docker*
  * *Nvidia*
  * *OpenAI*

* S3 *(Amazon S3 Bucket)*

For provider-specific syntax, see [Provider-Specific Syntax](/content/sql/ddl#sql-create-credential-syntax).
For provider-specific examples, see [Creating Credentials](/content/snippets/create-credentials).

### Parameters

<AccordionGroup>
  <Accordion title="OR REPLACE" id="or-replace-5" defaultOpen>
    Any existing *credential* with the same name will be dropped before creating this one
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-16" defaultOpen>
    Name of the *schema* that will contain the created *credential*; if no *schema* is specified, the
    *credential* will be created in the user's [default schema](/content/concepts/schemas#schema-default)
  </Accordion>

  <Accordion title="<credential name>" id="<credential-name>" defaultOpen>
    Name of the *credential* to create; must adhere to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria)
  </Accordion>

  <Accordion title="TYPE" id="type" defaultOpen>
    The type of *credential* to create. Supported types include:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Type</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>aws\_access\_key</code></td>
            <td>Authenticate to *Amazon Web Services (AWS)* via *Access Key*</td>
          </tr>

          <tr>
            <td><code>aws\_iam\_role</code></td>
            <td>Authenticate to *Amazon Web Services (AWS)* via *IAM Role*</td>
          </tr>

          <tr>
            <td><code>azure\_ad</code></td>
            <td>Authenticate to *Microsoft Azure* via *Active Directory*</td>
          </tr>

          <tr>
            <td><code>azure\_oauth</code></td>
            <td>Authenticate to *Microsoft Azure* via *OAuth*</td>
          </tr>

          <tr>
            <td><code>azure\_sas</code></td>
            <td>Authenticate to *Microsoft Azure* via *Shared Access Signature (SAS)* using an account-level access token, not a container-level one</td>
          </tr>

          <tr>
            <td><code>azure\_storage\_key</code></td>
            <td>Authenticate to *Microsoft Azure* via *Storage Key*</td>
          </tr>

          <tr>
            <td><code>confluent</code></td>
            <td>Authenticate to a *Confluent Kafka* cluster or schema registry</td>
          </tr>

          <tr>
            <td><code>docker</code></td>
            <td>Authenticate to a *Docker* repository</td>
          </tr>

          <tr>
            <td><code>gcs\_service\_account\_id</code></td>
            <td>Authenticate to *Google Cloud* via user ID & private key</td>
          </tr>

          <tr>
            <td><code>gcs\_service\_account\_keys</code></td>
            <td>Authenticate to *Google Cloud* via *JSON key*</td>
          </tr>

          <tr>
            <td><code>hdfs</code></td>
            <td>Authenticate to *HDFS*</td>
          </tr>

          <tr>
            <td><code>jdbc</code></td>
            <td>Authenticate via *Java Database Connectivity*</td>
          </tr>

          <tr>
            <td><code>kafka</code></td>
            <td>Authenticate to an *Apache Kafka* cluster or schema registry</td>
          </tr>

          <tr>
            <td><code>nvidia\_api\_key</code></td>
            <td>Authenticate to the *Nvidia AI* API</td>
          </tr>

          <tr>
            <td><code>openai\_api\_key</code></td>
            <td>Authenticate to the *OpenAI* API</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="IDENTITY" id="identity" defaultOpen>
    Username to use for authenticating with the *credential*.
  </Accordion>

  <Accordion title="SECRET" id="secret" defaultOpen>
    Password to use for authenticating with the *credential*.
  </Accordion>

  <Accordion title="WITH OPTIONS" id="with-options-4" defaultOpen>
    Optional indicator that a comma-delimited list of option/value assignments will follow.  See
    [Options](/content/sql/ddl#sql-credential-opts) for the full list of options.
  </Accordion>
</AccordionGroup>

### Examples

To create a *credential*, `auser_azure_active_dir_creds`, for
connecting to *Microsoft Azure Active Directory*:

```sql CREATE CREDENTIAL (Azure AD) Example theme={null}
CREATE CREDENTIAL auser_azure_active_dir_creds
TYPE = 'azure_ad',
IDENTITY = 'atypicaluser',
SECRET = 'Passw0rd!'
```

To create a *credential*, `kafka_cred`, for connecting to *Apache Kafka* via SSL:

```sql CREATE CREDENTIAL (Kafka SSL) Example theme={null}
CREATE CREDENTIAL kafka_cred
TYPE = 'kafka'
WITH OPTIONS
(
    'security.protocol' = 'SSL',
    'ssl.ca.location' = 'kifs://ssl/ca-bundle.crt',
    'ssl.certificate.location' = 'kifs://ssl/client.pem',
    'ssl.key.location' = 'kifs://ssl/client.key',
    'ssl.key.password' = 'Passw0rd!'
)
```

<a id="sql-credential-opts" />

### Options

The following is a list of possible credential options and their associated
providers.  For valid combinations of credential options per provider and
authentication mechanism, see [Provider-Specific Syntax](/content/sql/ddl#sql-create-credential-syntax).

| Option                       | Provider | Description                                                                                                                 |
| ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------- |
| `azure_storage_account_name` | Azure    | Azure storage account name *(only used if* `azure_tenant_id` *is specified)*                                                |
| `azure_tenant_id`            | Azure    | Azure Active Directory tenant identifier                                                                                    |
| `gcs_service_account_keys`   | GCS      | Text of the JSON file containing the GCS private key                                                                        |
| `hdfs_kerberos_keytab`       | HDFS     | Location of the Kerberos keytab file in [KiFS](/content/tools/kifs)                                                         |
| `hdfs_use_kerberos`          | HDFS     | Whether to attempt Kerberos authentication to HDFS                                                                          |
| `s3_aws_role_arn`            | S3       | AWS S3 IAM role                                                                                                             |
| `sasl.kerberos.keytab`       | Kafka    | Location of the Kerberos keytab file in [KiFS](/content/tools/kifs)                                                         |
| `sasl.kerberos.principal`    | Kafka    | Kerberos principal ID                                                                                                       |
| `sasl.kerberos.service.name` | Kafka    | Kerberos service name                                                                                                       |
| `sasl.mechanism`             | Kafka    | SASL scheme to use; one of: <br /> <br /> \* `PLAIN` <br /> \* `GSSAPI`                                                     |
| `sasl.password`              | Kafka    | SASL user password                                                                                                          |
| `sasl.username`              | Kafka    | SASL user ID                                                                                                                |
| `security.protocol`          | Kafka    | Security protocol to use for authentication; one of: <br /> <br /> \* `SSL` <br /> \* `SASL_SSL` <br /> \* `SASL_PLAINTEXT` |
| `ssl.ca.location`            | Kafka    | Location of CA certificates file in [KiFS](/content/tools/kifs)                                                             |
| `ssl.certificate.location`   | Kafka    | Location of client certificate in [KiFS](/content/tools/kifs)                                                               |
| `ssl.key.location`           | Kafka    | Location of client key in [KiFS](/content/tools/kifs)                                                                       |
| `ssl.key.password`           | Kafka    | Password to client key or trust store                                                                                       |

<a id="sql-create-credential-syntax" />

### Provider-Specific Syntax

Several authentication schemes across multiple providers are supported.

* [Azure](/content/sql/ddl#sql-create-credential-azure)
* [GCS](/content/sql/ddl#sql-create-credential-gcs)
* [HDFS](/content/sql/ddl#sql-create-credential-hdfs)
* [JDBC](/content/sql/ddl#sql-create-credential-jdbc)
* [Kafka (Apache)](/content/sql/ddl#sql-create-credential-kafka)
* [Kafka (Confluent)](/content/sql/ddl#sql-create-credential-confluent)
* [Remote Repository](/content/sql/ddl#sql-create-credential-repo)
* [S3](/content/sql/ddl#sql-create-credential-s3)

<a id="sql-create-credential-azure" />

#### Azure

Syntax below, examples [here](/content/snippets/create-credentials#snippet-sql-create-credential-azure).

<CodeGroup>
  ```sql Password theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'azure_storage_key',
  IDENTITY = '<azure storage account name>',
  SECRET = '<azure storage account key>'
  ```

  ```sql SAS Token theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'azure_sas',
  IDENTITY = '<azure storage account name>',
  SECRET = '<azure sas token>'
  ```

  ```sql Active Directory theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'azure_ad',
  IDENTITY = '<ad client id>',
  SECRET = '<ad client secret key>'
  WITH OPTIONS
  (
      STORAGE ACCOUNT NAME = '<azure storage account name>',
      TENANT ID = '<azure tenant id>'
  )
  ```
</CodeGroup>

<a id="sql-create-credential-gcs" />

#### GCS

Syntax below, examples [here](/content/snippets/create-credentials#snippet-sql-create-credential-gcs).

<CodeGroup>
  ```sql User ID & Key theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'gcs_service_account_id',
  IDENTITY = '<gcs account id>',
  SECRET = '<gcs account private key>'
  ```

  ```sql JSON Key theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'gcs_service_account_keys',
  WITH OPTIONS (GCS_SERVICE_ACCOUNT_KEYS = '<gcs account json key text>')
  ```
</CodeGroup>

<a id="sql-create-credential-hdfs" />

#### HDFS

Syntax below, examples [here](/content/snippets/create-credentials#snippet-sql-create-credential-hdfs).

<CodeGroup>
  ```sql Password theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'hdfs',
  IDENTITY = '<hdfs username>',
  SECRET = '<hdfs password>'
  ```

  ```sql Kerberos Keytab theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'hdfs',
  IDENTITY = '<hdfs username>'
  WITH OPTIONS (KERBEROS KEYTAB = 'kifs://<keytab file path>')
  ```

  ```sql Kerberos Token theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'hdfs',
  IDENTITY = '<hdfs username>'
  WITH OPTIONS (USE KERBEROS = 'true')
  ```
</CodeGroup>

<a id="sql-create-credential-jdbc" />

#### JDBC

Syntax below, examples [here](/content/snippets/create-credentials#snippet-sql-create-credential-jdbc).

```sql Password theme={null}
CREATE CREDENTIAL [<schema name>.]<credential name>
TYPE = 'jdbc',
IDENTITY = '<username>',
SECRET = '<password>'
```

<a id="sql-create-credential-kafka" />

#### Kafka (Apache)

Syntax below, examples [here](/content/snippets/create-credentials#snippet-sql-create-credential-kafka).

<CodeGroup>
  ```sql SSL with CA Cert theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'kafka'
  WITH OPTIONS
  (
      'security.protocol' = 'SSL',
      'ssl.ca.location' = 'kifs://<client ca certificates path>'
  )
  ```

  ```sql SSL with CA Cert/Client Auth theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'kafka'
  WITH OPTIONS
  (
      'security.protocol' = 'SSL',
      'ssl.ca.location' = 'kifs://<client ca certificates path>',
      'ssl.certificate.location' = 'kifs://<client certificate path>'
  )
  ```

  ```sql SSL with Encryption theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'kafka'
  WITH OPTIONS
  (
      'security.protocol' = 'SSL',
      'ssl.ca.location' = 'kifs://<client ca certificates path>',
      'ssl.certificate.location' = 'kifs://<client certificate path>',
      'ssl.key.location' = 'kifs://<client key path>',
      'ssl.key.password' = '<client key password>'
  )
  ```

  ```sql SASL theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'kafka'
  WITH OPTIONS
  (
      'security.protocol' = 'SASL_SSL',
      'sasl.mechanism' = 'PLAIN',
      'sasl.username' = '<sasl username>',
      'sasl.password' = '<sasl password>'
  )
  ```

  ```sql Kerberos theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'kafka'
  WITH OPTIONS
  (
      'security.protocol' = 'SASL_PLAINTEXT',
      'sasl.mechanism' = 'GSSAPI',
      'sasl.kerberos.service.name' = '<kerberos service name>',
      'sasl.kerberos.keytab' = 'kifs://<kerberos keytab file>',
      'sasl.kerberos.principal' = '<kerberos principal>'
  )
  ```

  ```sql Kerberos SSL theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'kafka'
  WITH OPTIONS
  (
      'security.protocol' = 'SASL_SSL',
      'sasl.mechanism' = 'GSSAPI',
      'sasl.kerberos.service.name' = '<kerberos service name>',
      'sasl.kerberos.keytab' = 'kifs://<kerberos keytab file>',
      'sasl.kerberos.principal' = '<kerberos principal>',
      'ssl.ca.location' = 'kifs://<client ca certificates path>',
      'ssl.certificate.location' = 'kifs://<client certificate path>',
      'ssl.key.location' = 'kifs://<client key path>',
      'ssl.key.password' = '<client key password>'
  )
  ```
</CodeGroup>

<a id="sql-create-credential-confluent" />

#### Kafka (Confluent)

Syntax below, examples [here](/content/snippets/create-credentials#snippet-sql-create-credential-confluent).

<CodeGroup>
  ```sql SSL with CA Cert theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'confluent'
  WITH OPTIONS
  (
      'security.protocol' = 'SSL',
      'ssl.ca.location' = 'kifs://<client ca certificates path>'
  )
  ```

  ```sql SSL with CA Cert/Client Auth theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'confluent'
  WITH OPTIONS
  (
      'security.protocol' = 'SSL',
      'ssl.ca.location' = 'kifs://<client ca certificates path>',
      'ssl.certificate.location' = 'kifs://<client certificate path>'
  )
  ```

  ```sql SSL with Encryption theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'confluent'
  WITH OPTIONS
  (
      'security.protocol' = 'SSL',
      'ssl.ca.location' = 'kifs://<client ca certificates path>',
      'ssl.certificate.location' = 'kifs://<client certificate path>',
      'ssl.key.location' = 'kifs://<client key path>',
      'ssl.key.password' = '<client key password>'
  )
  ```

  ```sql SASL theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'confluent'
  WITH OPTIONS
  (
      'security.protocol' = 'SASL_SSL',
      'sasl.mechanism' = 'PLAIN',
      'sasl.username' = '<sasl username>',
      'sasl.password' = '<sasl password>'
  )
  ```

  ```sql Kerberos theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'confluent'
  WITH OPTIONS
  (
      'security.protocol' = 'SASL_PLAINTEXT',
      'sasl.mechanism' = 'GSSAPI',
      'sasl.kerberos.service.name' = '<kerberos service name>',
      'sasl.kerberos.keytab' = 'kifs://<kerberos keytab file>',
      'sasl.kerberos.principal' = '<kerberos principal>'
  )
  ```

  ```sql Kerberos SSL theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'confluent'
  WITH OPTIONS
  (
      'security.protocol' = 'SASL_SSL',
      'sasl.mechanism' = 'GSSAPI',
      'sasl.kerberos.service.name' = '<kerberos service name>',
      'sasl.kerberos.keytab' = 'kifs://<kerberos keytab file>',
      'sasl.kerberos.principal' = '<kerberos principal>',
      'ssl.ca.location' = 'kifs://<client ca certificates path>',
      'ssl.certificate.location' = 'kifs://<client certificate path>',
      'ssl.key.location' = 'kifs://<client key path>',
      'ssl.key.password' = '<client key password>'
  )
  ```
</CodeGroup>

<a id="sql-create-credential-repo" />

#### Remote Repository

Syntax below, examples [here](/content/snippets/create-credentials#snippet-sql-create-credential-repo).

<CodeGroup>
  ```sql Docker theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'docker',
  IDENTITY = '<username>',
  SECRET = '<password>'
  ```

  ```sql Nvidia API theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'nvidia_api_key',
  SECRET = '<nvidia api key>'
  ```

  ```sql OpenAI API theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'openai_api_key',
  SECRET = '<openai api key>'
  ```
</CodeGroup>

<a id="sql-create-credential-s3" />

#### S3

Syntax below, examples [here](/content/snippets/create-credentials#snippet-sql-create-credential-s3).

<CodeGroup>
  ```sql S3 Access Key theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'aws_access_key',
  IDENTITY = '<aws access key id>',
  SECRET = '<aws secret access key>'
  ```

  ```sql IAM Role theme={null}
  CREATE CREDENTIAL [<schema name>.]<credential name>
  TYPE = 'aws_iam_role',
  IDENTITY = '<aws access key id>',
  SECRET = '<aws secret access key>'
  WITH OPTIONS (S3_AWS_ROLE_ARN = '<amazon resource name>')
  ```
</CodeGroup>

<a id="sql-alter-credential" />

## ALTER CREDENTIAL

Alters the properties of an existing
[credential](/content/sql/ddl#sql-create-credential).

```sql title="ALTER CREDENTIAL Syntax" theme={null}
ALTER CREDENTIAL [<schema name>.]<credential name>
SET PROPERTY
    <property name> = '<property value>'[,...]
```

Only users with `system_admin` or `system_user_admin`, or users with
`credential_admin` on the *credential*, may alter it.

### Parameters

<AccordionGroup>
  <Accordion title="<schema name>" id="<schema-name>-17" defaultOpen>
    Name of the *schema* containing the *credential* to alter
  </Accordion>

  <Accordion title="<credential name>" id="<credential-name>-2" defaultOpen>
    Name of the existing *credential* to alter.
  </Accordion>

  <Accordion title="SET PROPERTY" id="set-property" defaultOpen>
    Indicator that a comma-delimited list of property name/value assignments will follow. See
    [Set Properties](/content/sql/ddl#sql-alter-credential-prop) and [Options](/content/sql/ddl#sql-credential-opts) for the
    complete list of properties.
  </Accordion>
</AccordionGroup>

### Examples

To alter a *credential*, `auser_azure_active_dir_creds`, updating the secret:

```sql ALTER CREDENTIAL Example theme={null}
ALTER CREDENTIAL auser_azure_active_dir_creds
SET PROPERTY
    SECRET = 'atypicaluserNewPassw0rd!'
```

To alter a *credential*, `kafka_cred`, updating the keystore password:

```sql ALTER CREDENTIAL WITH OPTIONS Example theme={null}
ALTER CREDENTIAL kafka_cred
SET PROPERTY
    'ssl.key.password' = 'Passw0rd!?'
```

<a id="sql-alter-credential-prop" />

### Set Properties

All *credential* properties can be altered via
[ALTER CREDENTIAL](/content/sql/ddl#sql-alter-credential). The following are the property names and
descriptions to use when performing an alteration.

<AccordionGroup>
  <Accordion title="TYPE" id="type-2" defaultOpen>
    The type of *credential*. Supported types include:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Type</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>aws\_access\_key</code></td>
            <td>Authenticate to *Amazon Web Services (AWS)* via *Access Key*</td>
          </tr>

          <tr>
            <td><code>aws\_iam\_role</code></td>
            <td>Authenticate to *Amazon Web Services (AWS)* via *IAM Role*</td>
          </tr>

          <tr>
            <td><code>azure\_ad</code></td>
            <td>Authenticate to *Microsoft Azure* via *Active Directory*</td>
          </tr>

          <tr>
            <td><code>azure\_sas</code></td>
            <td>Authenticate to *Microsoft Azure* via *Shared Access Signature (SAS)*</td>
          </tr>

          <tr>
            <td><code>azure\_storage\_key</code></td>
            <td>Authenticate to *Microsoft Azure* via *Storage Key*</td>
          </tr>

          <tr>
            <td><code>confluent</code></td>
            <td>Authenticate to a *Confluent Kafka* cluster or schema registry</td>
          </tr>

          <tr>
            <td><code>docker</code></td>
            <td>Authenticate to a *Docker* repository</td>
          </tr>

          <tr>
            <td><code>gcs\_service\_account\_id</code></td>
            <td>Authenticate to *Google Cloud* via user ID & private key</td>
          </tr>

          <tr>
            <td><code>gcs\_service\_account\_keys</code></td>
            <td>Authenticate to *Google Cloud* via *JSON key*</td>
          </tr>

          <tr>
            <td><code>hdfs</code></td>
            <td>Authenticate to *HDFS*</td>
          </tr>

          <tr>
            <td><code>jdbc</code></td>
            <td>Authenticate via *Java Database Connectivity*</td>
          </tr>

          <tr>
            <td><code>kafka</code></td>
            <td>Authenticate to a *Kafka* cluster or schema registry</td>
          </tr>

          <tr>
            <td><code>nvidia\_api\_key</code></td>
            <td>Authenticate to the *Nvidia AI* API</td>
          </tr>

          <tr>
            <td><code>openai\_api\_key</code></td>
            <td>Authenticate to the *OpenAI* API</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="IDENTITY" id="identity-2" defaultOpen>
    Username to use for authenticating with the *credential*.
  </Accordion>

  <Accordion title="SECRET" id="secret-2" defaultOpen>
    Password to use for authenticating with the *credential*.
  </Accordion>

  <Accordion title="'<option>'" id="<option>" defaultOpen>
    Any option/value pair from the [credential options](/content/sql/ddl#sql-credential-opts) list.
  </Accordion>
</AccordionGroup>

<a id="sql-drop-credential" />

## DROP CREDENTIAL

Removes an existing [credential](/content/sql/ddl#sql-create-credential).

```sql title="DROP CREDENTIAL Syntax" theme={null}
DROP CREDENTIAL < [<schema name>.]<credential name> | * >
```

<Info>
  All [data sources](/content/sql/ddl#sql-create-data-source),
  [data sinks](/content/sql/ddl#sql-create-data-sink), and
  [ML container registries](/content/sql/ml#sql-ml-create-cr) that depend on a
  given *credential* must be dropped before it can be dropped.
</Info>

Only users with `system_admin` or `system_user_admin`, or users with
`credential_admin` on the *credential* to drop, may drop a *credential*.

### Parameters

<AccordionGroup>
  <Accordion title="<schema name>" id="<schema-name>-18" defaultOpen>
    Name of the *schema* containing the *credential* to drop
  </Accordion>

  <Accordion title="<credential name>" id="<credential-name>-3" defaultOpen>
    Name of the existing *credential* to remove; use `*` instead of *schema*/*credential* name to
    drop all *credentials*
  </Accordion>
</AccordionGroup>

### Examples

To drop a *credential*, `auser_azure_active_dir_creds`:

```sql DROP CREDENTIAL Example theme={null}
DROP CREDENTIAL auser_azure_active_dir_creds
```

<a id="sql-show-credential" />

## SHOW CREDENTIAL

Outputs the DDL statement required to reconstruct the given
[credential](/content/sql/ddl#sql-create-credential).

```sql title="SHOW CREDENTIAL Syntax" theme={null}
SHOW CREDENTIAL < [<schema name>.]<credential name> | * >
```

The `secret` value will be masked and would need to be replaced with the
actual `secret` value if attempting to reconstruct the *credential*.  Only
users with `system_admin` or `system_user_admin`, or users with
`credential_admin` or `credential_read` on the *credential* to show, may
show a *credential*.

<Info>
  The response to `SHOW CREDENTIAL` is a single-column result set
  with the DDL statement as the value in the `DDL` column.
</Info>

### Parameters

<AccordionGroup>
  <Accordion title="<schema name>" id="<schema-name>-19" defaultOpen>
    Name of the *schema* containing the *credential* to show
  </Accordion>

  <Accordion title="<credential name>" id="<credential-name>-4" defaultOpen>
    Name of the existing *credential* for which the DDL will be output; use `*` instead of
    *schema*/*credential* name to output the DDL of all *credentials*
  </Accordion>
</AccordionGroup>

### Examples

To output the DDL for a *credential*, `auser_azure_active_dir_creds`:

```sql SHOW CREDENTIAL Example theme={null}
SHOW CREDENTIAL auser_azure_active_dir_creds
```

To output the DDL for all *credentials*:

```sql SHOW CREDENTIAL (All Credentials) Example theme={null}
SHOW CREDENTIAL *
```

<a id="sql-desc-credential" />

## DESCRIBE CREDENTIAL

Outputs the configuration of an existing
[credential](/content/sql/ddl#sql-create-credential).

```sql title="DESCRIBE CREDENTIAL Syntax" theme={null}
DESC[RIBE] CREDENTIAL < [<schema name>.]<credential name> | * >
```

Only users with `system_admin` or `system_user_admin`, or users with
`credential_admin` or `credential_read` on the *credential* to describe, may
describe a *credential*.

### Parameters

<AccordionGroup>
  <Accordion title="<schema name>" id="<schema-name>-20" defaultOpen>
    Name of the *schema* containing the *credential* to describe
  </Accordion>

  <Accordion title="<credential name>" id="<credential-name>-5" defaultOpen>
    Name of the existing *credential* for which the configuration will be output; use `*` instead
    of *schema*/*credential* name to output the configuration of all *credentials*
  </Accordion>
</AccordionGroup>

### Response

The response to `DESCRIBE CREDENTIAL` is a four-column result set:

| Output Column         | Description                                                                                              |
| --------------------- | -------------------------------------------------------------------------------------------------------- |
| `CREDENTIAL_NAME`     | Name of the *credential*                                                                                 |
| `CREDENTIAL_TYPE`     | Type of the *credential*; see [CREATE CREDENTIAL](/content/sql/ddl#sql-create-credential) for values     |
| `CREDENTIAL_IDENTITY` | Username associated with the *credential*                                                                |
| `CREDENTIAL_OPTIONS`  | Options associated with the *credential*; see [Options](/content/sql/ddl#sql-credential-opts) for values |

### Examples

To show the configuration for a *credential*, `auser_azure_active_dir_creds`:

```sql DESCRIBE CREDENTIAL Example theme={null}
DESCRIBE CREDENTIAL auser_azure_active_dir_creds
```

To show the configuration for all *credentials*:

```sql DESCRIBE CREDENTIAL (All Credentials) Example theme={null}
DESCRIBE CREDENTIAL *
```

<a id="sql-create-data-source" />

## CREATE DATA SOURCE

Creates a new [data source](/content/concepts/data_sources), which contains
the location and connection information for a data store that is external to
*Kinetica*.  A *data source* serves as an authentication & access mechanism to a
remote resource and can optionally be used as a streaming source as well.

```sql title="CREATE DATA SOURCE Syntax" theme={null}
CREATE [OR REPLACE] [EXTERNAL] DATA SOURCE [<data source schema name>.]<data source name>
LOCATION = '<provider>[://[<host>[:<port>]]]'
[USER = '<username>']
[PASSWORD = '<password>']
[WITH OPTIONS (<option name> = '<option value>'[,...])]
```

A *data source* does not reference specific data files within the source; file
references (if applicable) can be made by using the *data source* in a
[CREATE EXTERNAL TABLE](/content/sql/ddl#sql-create-ext-table) call (for creating a persistent view of the
file data) or a [LOAD INTO](/content/sql/load#sql-load-file-server) call (for either a one-time
load or a subscribed loading of data from the external source to a locally
persisted [table](/content/sql/ddl#sql-create-table)).

<Info>
  The *data source* will be validated upon creation, by default, and
  will fail to be created if an authorized connection cannot be established.
</Info>

The following *data source* providers are supported:

* Azure *(Microsoft blob storage)*

* GCS *(Google Cloud Storage)*

* HDFS *(Apache Hadoop Distributed File System)*

* JDBC *(Java Database Connectivity, using a user-supplied driver or one of the*
  *drivers on the [supported list](/content/concepts/jdbc_drivers))*

* Kafka *(streaming feed)*

  * *Apache*
  * *Confluent*

* S3 *(Amazon S3 Bucket)*

<Info>
  - Azure anonymous *data sources* are only supported when both the container
    and the contained objects allow anonymous access.
  - HDFS systems with wire encryption are not supported.
  - Confluent & Kafka *data sources* require an associated
    [credential](/content/sql/ddl#sql-create-credential) for authentication.
</Info>

For provider-specific syntax, see [Provider-Specific Syntax](/content/sql/ddl#sql-create-data-source-syntax).
For provider-specific examples, see [Creating Data Sources](/content/snippets/create-data-sources).

### Parameters

<AccordionGroup>
  <Accordion title="OR REPLACE" id="or-replace-6" defaultOpen>
    Any existing *data source* with the same name will be dropped before creating this one
  </Accordion>

  <Accordion title="EXTERNAL" id="external" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-21" defaultOpen>
    Name of the *schema* that will contain the created *data source*; if no *schema* is specified,
    the *data source* will be created in the user's [default schema](/content/concepts/schemas#schema-default)
  </Accordion>

  <Accordion title="<data source name>" id="<data-source-name>" defaultOpen>
    Name of the *data source* to create; must adhere to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria)
  </Accordion>

  <Accordion title="<provider>" id="<provider>" defaultOpen>
    Provider of the *data source*

    Supported providers include:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Provider</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>AZURE</code></td>
            <td>Microsoft Azure blob storage</td>
          </tr>

          <tr>
            <td><code>CONFLUENT</code></td>
            <td>Confluent Kafka streaming feed <Note>The `LOCATION` can be a comma-delimited list of Kafka URLs, to be used for high-availability; only one of which will be streamed from at any given time.</Note></td>
          </tr>

          <tr>
            <td><code>GCS</code></td>
            <td>Google Cloud Storage</td>
          </tr>

          <tr>
            <td><code>HDFS</code></td>
            <td>Apache Hadoop Distributed File System</td>
          </tr>

          <tr>
            <td><code>JDBC</code></td>
            <td>JDBC connection, where <code>LOCATION</code> is the JDBC URL. <pre><code class="language-sql">LOCATION = 'jdbc:postgresql://example.com:5432/mydb'</code></pre> See the [supported list](/content/concepts/jdbc_drivers) for the full list of supported drivers, or specify one with <code>JDBC\_DRIVER\_JAR\_PATH</code> and <code>JDBC\_DRIVER\_CLASS\_NAME</code>.</td>
          </tr>

          <tr>
            <td><code>KAFKA</code></td>
            <td>Apache Kafka streaming feed <Note>The `LOCATION` can be a comma-delimited list of Kafka URLs, to be used for high-availability; only one of which will be streamed from at any given time.</Note></td>
          </tr>

          <tr>
            <td><code>S3</code></td>
            <td>Amazon S3 bucket</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="<host>" id="<host>" defaultOpen>
    Host to use to connect to the *data source*; the following providers have a default *host*, if
    `host` is left blank:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Provider</th>
            <th>Default Host</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td>*Azure*</td>
            <td><code>\<storage\_account\_name>.blob.core.windows.net</code></td>
          </tr>

          <tr>
            <td>*GCS*</td>
            <td><code>storage.googleapis.com</code></td>
          </tr>

          <tr>
            <td>*S3*</td>
            <td><code>\<region>.amazonaws.com</code></td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="<port>" id="<port>" defaultOpen>
    Port, for HDFS or Kafka, to use to connect to the *data source*
  </Accordion>

  <Accordion title="USER" id="user" defaultOpen>
    Optional user name, given in `<username>`, to use for authenticating to the
    *data source*
  </Accordion>

  <Accordion title="PASSWORD" id="password" defaultOpen>
    Optional password, given in `<password>`, to use for authenticating to the
    *data source*
  </Accordion>

  <Accordion title="WITH OPTIONS" id="with-options-5" defaultOpen>
    Optional indicator that a comma-delimited list of connection option/value assignments will
    follow.  See [Options](/content/sql/ddl#sql-ds-opts) for the full list of options.
  </Accordion>
</AccordionGroup>

### Examples

To create a *data source*, `kin_ds`, that connects to an Amazon S3 bucket,
`kinetica_ds`, in the **US East (N. Virginia)** region:

```sql CREATE DATA SOURCE Example theme={null}
CREATE DATA SOURCE kin_ds
LOCATION = 'S3'
USER = '<aws access id>'
PASSWORD = '<aws access key>'
WITH OPTIONS
(
    BUCKET NAME = 'kinetica-ds',
    REGION = 'us-east-1'
)
```

<a id="sql-ds-opts" />

### Options

| Option                             | Provider             | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `CREDENTIAL`                       | *Any*                | [Credential](/content/sql/ddl#sql-create-credential) object to use to authenticate to the remote system                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `VALIDATE`                         | *Any*                | Whether to test the connection to the *data source* upon creation; if `TRUE` *(default)*, the creation of a *data source* that cannot be connected to will fail; if `FALSE`, the *data source* will be created regardless of connectivity                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `WAIT TIMEOUT`                     | *Any* except `JDBC`  | Timeout in seconds for reading from the storage provider                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `USE_MANAGED_CREDENTIALS`          | `AZURE`, `GCS`, `S3` | Whether to connect to the storage provider with provider-managed credentials <br /> <br /> `AZURE`: Use the *Azure Instance Metadata Service (IMDS)* endpoint local to the Kinetica cluster to acquire credentials *(only for on-prem clusters deployed within Azure)* <br /> <br /> `GCS`: Satisfy the [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials) requirements for credentials, making sure any supporting server-side configuration (files, environment variables) is done on every node in the cluster *(only for on-prem clusters deployed within GCS)* <br /> <br /> `S3`: Use the [AWS Default Credential Provider Chain](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html) to acquire credentials, making sure any supporting server-side configuration (files, environment variables) is done on every node in the cluster *(only for on-prem clusters deployed within S3)* |
| `CONNECTION TIMEOUT`               | `HDFS`, `S3`         | Timeout in seconds for connecting to a given storage provider                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `CONTAINER NAME`                   | `AZURE`              | Azure storage container name                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `SAS TOKEN`                        | `AZURE`              | Azure storage account shared access signature token; this should be an account-level access token, not a container-level one                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `STORAGE ACCOUNT NAME`             | `AZURE`              | Azure storage account name *(only used if* `TENANT ID` *is specified)*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `TENANT ID`                        | `AZURE`              | Azure Active Directory tenant identifier                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `GCS_BUCKET_NAME`                  | `GCS`                | Name of the GCS bucket to use as the data source                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `GCS_PROJECT_ID`                   | `GCS`                | Name of the Google Cloud project to use for request billing                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `GCS_SERVICE_ACCOUNT_KEYS`         | `GCS`                | Text of the JSON key file containing the GCS private key                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `DELEGATION TOKEN`                 | `HDFS`               | Optional Kerberos delegation token for *worker nodes*; if not specified, the token will be acquired from HDFS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `KERBEROS KEYTAB`                  | `HDFS`               | Location of the Kerberos keytab file in [KiFS](/content/tools/kifs)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `USE KERBEROS`                     | `HDFS`               | Whether to attempt Kerberos authentication to HDFS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `JDBC_DRIVER_CLASS_NAME`           | `JDBC`               | JDBC driver class name *(optional, if the name is available in the* *JAR file's manifest)*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `JDBC_DRIVER_JAR_PATH`             | `JDBC`               | [KiFS](/content/tools/kifs) path of the JDBC driver JAR file to use                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `KAFKA_TOPIC_NAME`                 | `KAFKA`, `CONFLUENT` | Kafka topic to access                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `SCHEMA_REGISTRY_CREDENTIAL`       | `KAFKA`, `CONFLUENT` | [Credential](/content/sql/ddl#sql-create-credential) object to use to authenticate to the Confluent Schema Registry                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `SCHEMA_REGISTRY_LOCATION`         | `KAFKA`,             | Location of the Confluent Schema Registry in format: <br /> <br /> `[storage_path[:storage_port]]` <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `SCHEMA_REGISTRY_PORT`             | `KAFKA`, `CONFLUENT` | Port of the Confluent Schema Registry                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `BUCKET NAME`                      | `S3`                 | Amazon S3 bucket name                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `REGION`                           | `S3`                 | Amazon S3 region identifier                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `S3_AWS_ROLE_ARN`                  | `S3`                 | Amazon Resource Name (ARN) specifying the role                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `S3_ENCRYPTION_CUSTOMER_ALGORITHM` | `S3`                 | Algorithm used to encrypt/decrypt data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `S3_ENCRYPTION_CUSTOMER_KEY`       | `S3`                 | Key used to encrypt/decrypt data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `S3_USE_VIRTUAL_ADDRESSING`        | `S3`                 | Whether to use virtual addressing when referencing the S3 sink <br /> <br /> `true`: The requests URI should be specified in virtual-hosted-style format where the bucket name is part of the domain name in the URL <br /> <br /> `false`: Use path-style URI for requests                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `S3_VERIFY_SSL`                    | `S3`                 | Whether to verify SSL connections <br /> <br /> `true`: Verify SSL connections *(default)* <br /> <br /> `false`: Don't verify SSL connections; for testing purposes, bypassing TLS errors, self-signed certificates, etc.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |

<a id="sql-create-data-source-syntax" />

### Provider-Specific Syntax

Several authentication schemes across multiple providers are supported.

* [Azure](/content/sql/ddl#sql-create-data-source-azure)
* [GCS](/content/sql/ddl#sql-create-data-source-gcs)
* [HDFS](/content/sql/ddl#sql-create-data-source-hdfs)
* [JDBC](/content/sql/ddl#sql-create-data-source-jdbc)
* [Kafka (Apache)](/content/sql/ddl#sql-create-data-source-kafka)
* [Kafka (Confluent)](/content/sql/ddl#sql-create-data-source-confluent)
* [S3](/content/sql/ddl#sql-create-data-source-s3)

<a id="sql-create-data-source-azure" />

#### Azure

Syntax below, examples [here](/content/snippets/create-data-sources#snippet-sql-create-data-source-azure).

<CodeGroup>
  ```sql Credential theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'AZURE[://<host>]'
  WITH OPTIONS
  (
      CREDENTIAL = '[<credential schema name>.]<credential name>',
      CONTAINER NAME = '<azure container name>'
  )
  ```

  ```sql Public (No Auth) theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'AZURE[://<host>]'
  USER = '<azure storage account name>'
  WITH OPTIONS (CONTAINER NAME = '<azure container name>')
  ```

  ```sql Managed Credentials theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'AZURE[://<host>]'
  [USER = '<ad client id>']
  WITH OPTIONS
  (
      USE_MANAGED_CREDENTIALS = true,
      STORAGE ACCOUNT NAME = '<azure storage account name>',
      CONTAINER NAME = '<azure container name>',
      TENANT ID = '<ad tenant id>'
  )
  ```

  ```sql Password theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'AZURE[://<host>]'
  USER = '<azure storage account name>'
  PASSWORD = '<azure storage account key>'
  WITH OPTIONS (CONTAINER NAME = '<azure container name>')
  ```

  ```sql SAS Token theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'AZURE[://<host>]'
  USER = '<azure storage account name>'
  WITH OPTIONS
  (
      SAS TOKEN = '<sas token>',
      CONTAINER NAME = '<azure container name>'
  )
  ```

  ```sql Active Directory theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'AZURE[://<host>]'
  USER = '<ad client id>'
  PASSWORD = '<ad client secret key>'
  WITH OPTIONS
  (
      STORAGE ACCOUNT NAME = '<azure storage account name>',
      CONTAINER NAME = '<azure container name>',
      TENANT ID = '<ad tenant id>'
  )
  ```
</CodeGroup>

<a id="sql-create-data-source-gcs" />

#### GCS

Syntax below, examples [here](/content/snippets/create-data-sources#snippet-sql-create-data-source-gcs).

<CodeGroup>
  ```sql Credential theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'GCS[://<host>]'
  WITH OPTIONS
  (
  	CREDENTIAL = '[<credential schema name>.]<credential name>',
  	[GCS_PROJECT_ID = '<gcs project id>',]
  	GCS_BUCKET_NAME = '<gcs bucket name>'
  )
  ```

  ```sql Managed Credentials theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'GCS[://<host>]'
  WITH OPTIONS
  (
  	USE_MANAGED_CREDENTIALS = true,
  	[GCS_PROJECT_ID = '<gcs project id>',]
  	GCS_BUCKET_NAME = '<gcs bucket name>'
  )
  ```

  ```sql Public (No Auth) theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'GCS[://<host>]'
  WITH OPTIONS
  (
  	[GCS_PROJECT_ID = '<gcs project id>',]
  	GCS_BUCKET_NAME = '<gcs bucket name>'
  )
  ```

  ```sql User ID & Key theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'GCS[://<host>]'
  USER = '<gcs account id>'
  PASSWORD = '<gcs account private key>'
  WITH OPTIONS
  (
  	[GCS_PROJECT_ID = '<gcs project id>',]
  	GCS_BUCKET_NAME = '<gcs bucket name>'
  )
  ```

  ```sql JSON Key theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'GCS[://<host>]'
  WITH OPTIONS
  (
  	GCS_SERVICE_ACCOUNT_KEYS = '<gcs account json key text>',
  	[GCS_PROJECT_ID = '<gcs project id>',]
  	GCS_BUCKET_NAME = '<gcs bucket name>'
  )
  ```
</CodeGroup>

<a id="sql-create-data-source-hdfs" />

#### HDFS

Syntax below, examples [here](/content/snippets/create-data-sources#snippet-sql-create-data-source-hdfs).

<CodeGroup>
  ```sql Credential theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'HDFS://<host>:<port>'
  WITH OPTIONS (CREDENTIAL = '[<credential schema name>.]<credential name>')
  ```

  ```sql Password theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'HDFS://<host>:<port>'
  USER = '<hdfs username>'
  PASSWORD = '<hdfs password>'
  ```

  ```sql Kerberos Keytab theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'HDFS://<host>:<port>'
  USER = '<hdfs username>'
  WITH OPTIONS (KERBEROS KEYTAB = 'kifs://<keytab file path>')
  ```

  ```sql Kerberos Token theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'HDFS://<host>:<port>'
  USER = '<hdfs username>'
  WITH OPTIONS (USE KERBEROS = true)
  ```
</CodeGroup>

<a id="sql-create-data-source-jdbc" />

#### JDBC

Syntax below, examples [here](/content/snippets/create-data-sources#snippet-sql-create-data-source-jdbc).

<CodeGroup>
  ```sql Credential theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = '<jdbc url>'
  WITH OPTIONS
  (
  	CREDENTIAL = '[<credential schema name>.]<credential name>',
  	JDBC_DRIVER_CLASS_NAME = '<jdbc driver class full path>',
  	JDBC_DRIVER_JAR_PATH = 'kifs://<jdbc driver jar path>'
  )
  ```

  ```sql Password theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = '<jdbc url>'
  USER = '<jdbc username>'
  PASSWORD = '<jdbc password>'
  WITH OPTIONS
  (
  	JDBC_DRIVER_CLASS_NAME = '<jdbc driver class full path>',
  	JDBC_DRIVER_JAR_PATH = 'kifs://<jdbc driver jar path>'
  )
  ```
</CodeGroup>

<a id="sql-create-data-source-kafka" />

#### Kafka (Apache)

Syntax below, examples [here](/content/snippets/create-data-sources#snippet-sql-create-data-source-kafka).

<CodeGroup>
  ```sql Credential theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'KAFKA://<host>:<port>'
  WITH OPTIONS
  (
      CREDENTIAL = '[<credential schema name>.]<credential name>',
      KAFKA_TOPIC_NAME = '<kafka topic name>'
  )
  ```

  ```sql Credential w/ Schema Registry theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'KAFKA://<host>:<port>'
  WITH OPTIONS
  (
      CREDENTIAL = '[<credential schema name>.]<credential name>',
      KAFKA_TOPIC_NAME = '<kafka topic name>',
      SCHEMA_REGISTRY_CREDENTIAL = '[<sr credential schema name>.]<sr credential name>',
      SCHEMA_REGISTRY_LOCATION = '<schema registry url>'
  )
  ```

  ```sql Public (No Auth) theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'KAFKA://<host>:<port>'
  WITH OPTIONS (KAFKA_TOPIC_NAME = '<kafka topic name>')
  ```
</CodeGroup>

<a id="sql-create-data-source-confluent" />

#### Kafka (Confluent)

Syntax below, examples [here](/content/snippets/create-data-sources#snippet-sql-create-data-source-confluent).

<CodeGroup>
  ```sql Credential theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'CONFLUENT://<host>:<port>'
  WITH OPTIONS
  (
      CREDENTIAL = '[<credential schema name>.]<credential name>',
      KAFKA_TOPIC_NAME = '<kafka topic name>'
  )
  ```

  ```sql Credential w/ Schema Registry theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'CONFLUENT://<host>:<port>'
  WITH OPTIONS
  (
      CREDENTIAL = '[<credential schema name>.]<credential name>',
      KAFKA_TOPIC_NAME = '<kafka topic name>',
      SCHEMA_REGISTRY_CREDENTIAL = '[<sr credential schema name>.]<sr credential name>',
      SCHEMA_REGISTRY_LOCATION = '<schema registry url>'
  )
  ```

  ```sql Public (No Auth) theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'CONFLUENT://<host>:<port>'
  WITH OPTIONS (KAFKA_TOPIC_NAME = '<kafka topic name>')
  ```
</CodeGroup>

<a id="sql-create-data-source-s3" />

#### S3

Syntax below, examples [here](/content/snippets/create-data-sources#snippet-sql-create-data-source-s3).

<CodeGroup>
  ```sql Credential theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'S3[://<host>]'
  WITH OPTIONS
  (
      CREDENTIAL = '[<credential schema name>.]<credential name>',
      BUCKET NAME = '<aws bucket name>',
      REGION = '<aws region>'
  )
  ```

  ```sql Public (No Auth) theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'S3[://<host>]'
  WITH OPTIONS
  (
      BUCKET NAME = '<aws bucket name>',
      REGION = '<aws region>'
  )
  ```

  ```sql Managed Credentials theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'S3[://<host>]'
  WITH OPTIONS
  (
      USE_MANAGED_CREDENTIALS = true,
      BUCKET NAME = '<aws bucket name>',
      REGION = '<aws region>'
  )
  ```

  ```sql Access Key theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'S3[://<host>]'
  USER = '<aws access key id>'
  PASSWORD = '<aws secret access key>'
  WITH OPTIONS
  (
      BUCKET NAME = '<aws bucket name>',
      REGION = '<aws region>'
  )
  ```

  ```sql IAM Role theme={null}
  CREATE DATA SOURCE [<data source schema name>.]<data source name>
  LOCATION = 'S3[://<host>]'
  USER = '<aws access key id>'
  PASSWORD = '<aws secret access key>'
  WITH OPTIONS
  (
      S3_AWS_ROLE_ARN = '<aws iam role arn>',
      BUCKET NAME = '<aws bucket name>',
      REGION = '<aws region>'
  )
  ```
</CodeGroup>

<a id="sql-alter-data-source" />

## ALTER DATA SOURCE

Alters the connection parameters of an existing
[data source](/content/sql/ddl#sql-create-data-source).

```sql title="ALTER DATA SOURCE Syntax" theme={null}
ALTER [EXTERNAL] DATA SOURCE [<data source schema name>.]<data source name>
SET PROPERTY
    <property name> = '<property value>'[,...]
```

<Info>
  The *data source* will be validated upon alteration, by default, and
  will fail to be altered if an authorized connection cannot be established.
</Info>

### Parameters

<AccordionGroup>
  <Accordion title="EXTERNAL" id="external-2" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-22" defaultOpen>
    Name of the *schema* containing the *data source* to alter
  </Accordion>

  <Accordion title="<data source name>" id="<data-source-name>-2" defaultOpen>
    Name of the *data source* to alter
  </Accordion>

  <Accordion title="SET PROPERTY" id="set-property-2" defaultOpen>
    Indicator that a comma-delimited list of alterations to make will follow.

    See [Set Properties](/content/sql/ddl#sql-alter-data-source-prop) for the complete list of properties.
  </Accordion>
</AccordionGroup>

### Examples

To alter a *data source*, `kin_ds`, updating the username & password:

```sql ALTER DATA SOURCE Example theme={null}
ALTER DATA SOURCE kin_ds
SET PROPERTY
    USER = '<new aws access id>',
    PASSWORD = '<new aws access key>'
```

<a id="sql-alter-data-source-prop" />

### Set Properties

All *data source* properties can be altered via [ALTER DATA SOURCE](/content/sql/ddl#sql-alter-data-source).
The following are the property names and descriptions to use when performing an
alteration.

#### Provider-Agnostic Properties

<AccordionGroup>
  <Accordion title="LOCATION" id="location" defaultOpen>
    Location of the *data source*; see [Provider-Specific Syntax](/content/sql/ddl#sql-create-data-source-syntax) for details

    The *data source* can be from any of the following *providers*:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Provider</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>AZURE</code></td>
            <td>Microsoft Azure blob storage</td>
          </tr>

          <tr>
            <td><code>CONFLUENT</code></td>
            <td>Confluent Kafka streaming feed</td>
          </tr>

          <tr>
            <td><code>GCS</code></td>
            <td>Google Cloud Storage</td>
          </tr>

          <tr>
            <td><code>HDFS</code></td>
            <td>Apache Hadoop Distributed File System</td>
          </tr>

          <tr>
            <td><code>JDBC</code></td>
            <td>JDBC connection, where <code>LOCATION</code> is the JDBC or CData JDBC URL. See the [supported list](/content/concepts/jdbc_drivers) for the full list of supported drivers, or specify one with <code>JDBC\_DRIVER\_JAR\_PATH</code> and <code>JDBC\_DRIVER\_CLASS\_NAME</code>.</td>
          </tr>

          <tr>
            <td><code>KAFKA</code></td>
            <td>Apache Kafka streaming feed</td>
          </tr>

          <tr>
            <td><code>S3</code></td>
            <td>Amazon S3 bucket</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="USER" id="user-2" defaultOpen>
    User name, given in `<username>`, to use for authenticating to the *data source*
  </Accordion>

  <Accordion title="PASSWORD" id="password-2" defaultOpen>
    Password, given in `<password>`, to use for authenticating to the *data source*
  </Accordion>

  <Accordion title="CREDENTIAL" id="credential" defaultOpen>
    [Credential](/content/sql/ddl#sql-create-credential) object to use to authenticate to the remote system
  </Accordion>

  <Accordion title="VALIDATE" id="validate" defaultOpen>
    Whether to test the connection to the data source upon creation; if `TRUE`, the creation of a
    *data source* that cannot be connected to will fail; if `FALSE`, the *data source* will be
    created regardless of connectivity.  Default is `TRUE`.
  </Accordion>
</AccordionGroup>

#### Provider-Specific Properties

| Option                             | Provider             | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `WAIT TIMEOUT`                     | *Any* except `JDBC`  | Timeout in seconds for reading from the storage provider                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `USE_MANAGED_CREDENTIALS`          | `AZURE`, `GCS`, `S3` | Whether to connect to the storage provider with provider-managed credentials <br /> <br /> `AZURE`: Use the *Azure Instance Metadata Service (IMDS)* endpoint local to the Kinetica cluster to acquire credentials *(only for on-prem clusters deployed within Azure)* <br /> <br /> `GCS`: Satisfy the [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials) requirements for credentials, making sure any supporting server-side configuration (files, environment variables) is done on every node in the cluster *(only for on-prem clusters deployed within GCS)* <br /> <br /> `S3`: Use the [AWS Default Credential Provider Chain](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html) to acquire credentials, making sure any supporting server-side configuration (files, environment variables) is done on every node in the cluster *(only for on-prem clusters deployed within S3)* |
| `CONNECTION TIMEOUT`               | `HDFS`, `S3`         | Timeout in seconds for connecting to a given storage provider                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `CONTAINER NAME`                   | `AZURE`              | Azure storage container name                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `SAS TOKEN`                        | `AZURE`              | Azure storage account shared access signature token; this should be an account-level access token, not a container-level one                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `STORAGE ACCOUNT NAME`             | `AZURE`              | Azure storage account name *(only used if* `TENANT ID` *is specified)*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `TENANT ID`                        | `AZURE`              | Azure Active Directory tenant identifier                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `GCS_BUCKET_NAME`                  | `GCS`                | Name of the GCS bucket to use as the data source                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `GCS_PROJECT_ID`                   | `GCS`                | Name of the Google Cloud project to use for request billing                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `GCS_SERVICE_ACCOUNT_KEYS`         | `GCS`                | Text of the JSON key file containing the GCS private key                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `DELEGATION TOKEN`                 | `HDFS`               | Optional Kerberos delegation token for *worker nodes*; if not specified, the token will be acquired from HDFS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `KERBEROS KEYTAB`                  | `HDFS`               | Location of the Kerberos keytab file in [KiFS](/content/tools/kifs)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `USE KERBEROS`                     | `HDFS`               | Whether to attempt Kerberos authentication to HDFS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `JDBC_DRIVER_CLASS_NAME`           | `JDBC`               | JDBC driver class name *(optional, if the name is available in the* *JAR file's manifest)*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `JDBC_DRIVER_JAR_PATH`             | `JDBC`               | [KiFS](/content/tools/kifs) path of the JDBC driver JAR file to use                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `KAFKA_TOPIC_NAME`                 | `KAFKA`, `CONFLUENT` | Kafka topic to access                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `SCHEMA_REGISTRY_CREDENTIAL`       | `KAFKA`, `CONFLUENT` | [Credential](/content/sql/ddl#sql-create-credential) object to use to authenticate to the Confluent Schema Registry                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `SCHEMA_REGISTRY_LOCATION`         | `KAFKA`,             | Location of the Confluent Schema Registry in format: <br /> <br /> `[storage_path[:storage_port]]` <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `SCHEMA_REGISTRY_PORT`             | `KAFKA`, `CONFLUENT` | Port of the Confluent Schema Registry                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `BUCKET NAME`                      | `S3`                 | Amazon S3 bucket name                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `REGION`                           | `S3`                 | Amazon S3 region identifier                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `S3_AWS_ROLE_ARN`                  | `S3`                 | Amazon Resource Name (ARN) specifying the role                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `S3_ENCRYPTION_CUSTOMER_ALGORITHM` | `S3`                 | Algorithm used to encrypt/decrypt data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `S3_ENCRYPTION_CUSTOMER_KEY`       | `S3`                 | Key used to encrypt/decrypt data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `S3_USE_VIRTUAL_ADDRESSING`        | `S3`                 | Whether to use virtual addressing when referencing the S3 sink <br /> <br /> `true`: The requests URI should be specified in virtual-hosted-style format where the bucket name is part of the domain name in the URL <br /> <br /> `false`: Use path-style URI for requests                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `S3_VERIFY_SSL`                    | `S3`                 | Whether to verify SSL connections <br /> <br /> `true`: Verify SSL connections *(default)* <br /> <br /> `false`: Don't verify SSL connections; for testing purposes, bypassing TLS errors, self-signed certificates, etc.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |

<a id="sql-list-data-source" />

## LIST DATA SOURCE

Outputs a list of tables accessible through a JDBC
[data source](/content/sql/ddl#sql-create-data-source).

```sql title="LIST DATA SOURCE Syntax" theme={null}
LIST [DATA SOURCE] [<schema name>.]<data source name>
[WITH OPTIONS (<option name> = '<option value>'[,...])]
```

<Info>
  The response to `LIST DATA SOURCE` is a single-column result set
  of table names in `<schema_name>.<table_name>` format.
</Info>

### Parameters

<AccordionGroup>
  <Accordion title="DATA SOURCE" id="data-source-2" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-23" defaultOpen>
    Name of the *schema* containing the *data source* to list
  </Accordion>

  <Accordion title="<data source name>" id="<data-source-name>-3" defaultOpen>
    Name of the *data source* whose accessible tables will be listed
  </Accordion>

  <Accordion title="WITH OPTIONS" id="with-options-6" defaultOpen>
    Optional indicator that a comma-delimited list of filtering option/value assignments will
    follow.  See [Options](/content/sql/ddl#sql-list-data-source-opts) for the full list of options.
  </Accordion>
</AccordionGroup>

### Examples

To list all the tables accessible through a *data source*,
`kin_ds_jdbc`:

```sql LIST DATA SOURCE (All Tables) Example theme={null}
LIST DATA SOURCE kin_ds_jdbc
```

To list all tables in a specific schema:

```sql LIST DATA SOURCE (Filter by Schema) Example theme={null}
LIST DATA SOURCE kin_ds_jdbc
WITH OPTIONS (SCHEMA = 'ki_catalog')
```

To list tables matching a specific name pattern, regardless of catalog/schema:

```sql LIST DATA SOURCE (Filter by Table) Example theme={null}
LIST DATA SOURCE kin_ds_jdbc
WITH OPTIONS (TABLE = '%role%')
```

<a id="sql-list-data-source-opts" />

### Options

The `_` and `%` characters can be used in any of these options to match
any single character or any number of characters in object names, respectively.

If multiple options are used, the tables must match all specified criteria.

<AccordionGroup>
  <Accordion title="CATALOG" id="catalog" defaultOpen>
    Only show tables within the specified catalog(s)
  </Accordion>

  <Accordion title="SCHEMA" id="schema-3" defaultOpen>
    Only show tables within the specified schema(s)
  </Accordion>

  <Accordion title="TABLE" id="table-3" defaultOpen>
    Only show tables matching the specified name(s)
  </Accordion>
</AccordionGroup>

<a id="sql-drop-data-source" />

## DROP DATA SOURCE

Removes an existing [data source](/content/sql/ddl#sql-create-data-source).

```sql title="DROP DATA SOURCE Syntax" theme={null}
DROP [EXTERNAL] DATA SOURCE [<schema name>.]<data source name>
```

<Info>
  Any [external tables](/content/sql/ddl#sql-create-ext-table) or
  subscriptions initiated by a [LOAD INTO](/content/sql/load#sql-load-into) command that depend
  on a given *data source* must be dropped before it can be dropped.
</Info>

### Parameters

<AccordionGroup>
  <Accordion title="EXTERNAL" id="external-3" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-24" defaultOpen>
    Name of the *schema* containing the *data source* to remove
  </Accordion>

  <Accordion title="<data source name>" id="<data-source-name>-4" defaultOpen>
    Name of the *data source* to remove
  </Accordion>
</AccordionGroup>

### Examples

To drop a *data source*, `kin_ds`:

```sql DROP DATA SOURCE Example theme={null}
DROP DATA SOURCE kin_ds
```

<a id="sql-show-data-source" />

## SHOW DATA SOURCE

Outputs the DDL statement required to reconstruct the given
[data source](/content/sql/ddl#sql-create-data-source).

```sql title="SHOW DATA SOURCE Syntax" theme={null}
SHOW [EXTERNAL] DATA SOURCE < [<schema name>.]<data source name> | * >
```

The `PASSWORD` value will be masked and would need to be replaced with the
actual password if attempting to reconstruct the *data source*.

<Info>
  The response to `SHOW DATA SOURCE` is a single-column result set
  with the DDL statement as the value in the `DDL` column.
</Info>

### Parameters

<AccordionGroup>
  <Accordion title="EXTERNAL" id="external-4" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-25" defaultOpen>
    Name of the *schema* containing the *data source* to show
  </Accordion>

  <Accordion title="<data source name>" id="<data-source-name>-5" defaultOpen>
    Name of the *data source* for which the DDL will be output; use `*` instead of
    *schema*/*data source* name to output the DDL of all *data sources*
  </Accordion>
</AccordionGroup>

### Examples

To output the DDL for a *data source*, `kin_ds`:

```sql SHOW DATA SOURCE Example theme={null}
SHOW DATA SOURCE kin_ds
```

To output the DDL for all *data sources*:

```sql SHOW DATA SOURCE (All Data Sources) Example theme={null}
SHOW DATA SOURCE *
```

<a id="sql-desc-data-source" />

## DESCRIBE DATA SOURCE

Outputs the configuration of an existing
[data source](/content/sql/ddl#sql-create-data-source).

```sql title="SHOW DATA SOURCE Syntax" theme={null}
DESC[RIBE] [EXTERNAL] DATA SOURCE < [<schema name>.]<data source name> | * >
```

### Parameters

<AccordionGroup>
  <Accordion title="EXTERNAL" id="external-5" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-26" defaultOpen>
    Name of the *schema* containing the *data source* to describe
  </Accordion>

  <Accordion title="<data source name>" id="<data-source-name>-6" defaultOpen>
    Name of the *data source* whose configuration will be output; use `*` instead of
    *schema*/*data source* name to output the configuration of all *data sources*
  </Accordion>
</AccordionGroup>

### Response

The response to `DESCRIBE DATA SOURCE` is a three-column result set:

| Output Column           | Description                                             |
| ----------------------- | ------------------------------------------------------- |
| `DATA_SOURCE`           | Name of the data source                                 |
| `STORAGE_PROVIDER_TYPE` | Keyword associated with storage provider                |
| `ADDITIONAL_INFO`       | *Data source* configuration; passwords will be redacted |

### Examples

To show the configuration for a *data source*, `kin_ds`:

```sql DESCRIBE DATA SOURCE Example theme={null}
DESCRIBE DATA SOURCE kin_ds
```

To show the configuration for all *data sources*:

```sql DESCRIBE DATA SOURCE (All Data Sources) Example theme={null}
DESCRIBE DATA SOURCE *
```

<a id="sql-create-data-sink" />

## CREATE DATA SINK

Creates a new [data sink](/content/concepts/data_sinks), which contains the
location and connection information for a data consumer that is *generally*
external to *Kinetica*.  A *data sink* serves as an authentication & access
mechanism to the remote resource.

```sql title="CREATE DATA SINK Syntax" theme={null}
CREATE [OR REPLACE] [EXTERNAL] DATA SINK [<schema name>.]<data sink name>
LOCATION = '<consumer>://<target>[:<port>]'
[WITH OPTIONS (<option name> = '<option value>'[,...])]
```

A *data sink* can be referenced in an [EXPORT ... INTO](/content/sql/export#sql-export) call (for
exporting local table data to a remote system) or a
[CREATE STREAM](/content/sql/ddl#sql-create-stream) call (for streaming local table data to a
remote system).

<Info>
  The *data sink* will be validated upon creation, by default, and
  will fail to be created if an authorized connection cannot be established.
</Info>

The following *data sink* consumers are supported:

* Azure *(Microsoft blob storage)*
* GCS *(Google Cloud Storage)*
* HDFS *(Apache Hadoop Distributed File System)*
* JDBC *(Java Database Connectivity, using a user-supplied driver or one of the*
  *drivers on the [supported list](/content/concepts/jdbc_drivers))*
* Kafka *(Apache Kafka streaming feed)*
* Local *(Table within the same Kinetica instance)*
* S3 *(Amazon S3 Bucket)*
* Webhook *(HTTP/HTTPS)*

<Info>
  Kafka *data sinks* will be validated upon creation, by default, and will
  fail to be created if an authorized connection cannot be established.
</Info>

For consumer-specific syntax, see [Consumer-Specific Syntax](/content/sql/ddl#sql-create-data-sink-syntax).
For consumer-specific examples, see [Creating Data Sinks](/content/snippets/create-data-sinks).

### Parameters

<AccordionGroup>
  <Accordion title="OR REPLACE" id="or-replace-7" defaultOpen>
    Any existing *data sink* with the same name will be dropped before creating this one
  </Accordion>

  <Accordion title="EXTERNAL" id="external-6" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-27" defaultOpen>
    Name of the *schema* that will contain the created *data sink*; if no *schema* is specified,
    the *data sink* will be created in the user's [default schema](/content/concepts/schemas#schema-default)
  </Accordion>

  <Accordion title="<data sink name>" id="<data-sink-name>" defaultOpen>
    Name of the *data sink* to create; must adhere to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria)
  </Accordion>

  <Accordion title="<consumer>" id="<consumer>" defaultOpen>
    Consumer of the *data sink*

    Supported consumers include:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Consumer</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>AZURE</code></td>
            <td>Microsoft Azure blob storage</td>
          </tr>

          <tr>
            <td><code>GCS</code></td>
            <td>Google Cloud Storage</td>
          </tr>

          <tr>
            <td><code>HDFS</code></td>
            <td>Apache Hadoop Distributed File System</td>
          </tr>

          <tr>
            <td><code>HTTP</code></td>
            <td>Unsecured webhook</td>
          </tr>

          <tr>
            <td><code>HTTPS</code></td>
            <td>Secured webhook</td>
          </tr>

          <tr>
            <td><code>JDBC</code></td>
            <td>JDBC connection, where <code>LOCATION</code> is the JDBC URL. <pre><code class="language-sql">LOCATION = 'jdbc:postgresql://example.com:5432/mydb'</code></pre> See the [supported list](/content/concepts/jdbc_drivers) for the full list of supported drivers, or specify one with <code>JDBC\_DRIVER\_JAR\_PATH</code> and <code>JDBC\_DRIVER\_CLASS\_NAME</code>.</td>
          </tr>

          <tr>
            <td><code>KAFKA</code></td>
            <td>Apache Kafka broker</td>
          </tr>

          <tr>
            <td><code>TABLE</code></td>
            <td>Local Kinetica table residing in the same database as the *data sink*: <pre><code class="language-sql">LOCATION = 'TABLE://example.employee\_backup'</code></pre></td>
          </tr>

          <tr>
            <td><code>S3</code></td>
            <td>Amazon S3 bucket</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="<target>" id="<target>" defaultOpen>
    Target to connect to via *data sink*; the following consumers have a default *host target*, if
    `target` is left blank:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Consumer</th>
            <th>Default Host</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td>*Azure*</td>
            <td><code>\<storage\_account\_name>.blob.core.windows.net</code></td>
          </tr>

          <tr>
            <td>*GCS*</td>
            <td><code>storage.googleapis.com</code></td>
          </tr>

          <tr>
            <td>*S3*</td>
            <td><code>\<region>.amazonaws.com</code></td>
          </tr>
        </tbody>
      </table>
    </div>

    <Info>
      For local Kinetica tables, `target` is the name of the name of the target table:

      ```
      [<target table schema name>].<target table name>
      ```
    </Info>
  </Accordion>

  <Accordion title="<port>" id="<port>-2" defaultOpen>
    Port to connect to via the *data sink*, if applicable
  </Accordion>

  <Accordion title="WITH OPTIONS" id="with-options-7" defaultOpen>
    Optional indicator that a comma-delimited list of connection option/value assignments will
    follow.  See [Options](/content/sql/ddl#sql-dsink-opts) for the full list of options.
  </Accordion>
</AccordionGroup>

### Examples

To create a *data sink*, `kin_dsink`, that connects to an Apache Kafka broker:

```sql CREATE DATA SINK Example theme={null}
CREATE DATA SINK kin_dsink
LOCATION = 'kafka://kafka.abc.com:9092'
WITH OPTIONS
(
    CREDENTIAL = 'kafka_credential',
    KAFKA_TOPIC_NAME = 'kafka_topic'
)
```

<a id="sql-dsink-opts" />

### Options

| Option                             | Consumer                 | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `CREDENTIAL`                       | *Any*                    | [Credential](/content/sql/ddl#sql-create-credential) object to use to authenticate to the remote consumer                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `VALIDATE`                         | *Any*                    | Whether to test the connection to the *data sink* upon creation; if `TRUE` *(default)*, the creation of a *data sink* that cannot be connected to will fail; if `FALSE`, the *data sink* will be created regardless of connectivity                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `WAIT TIMEOUT`                     | *Any* except `JDBC`      | Timeout in seconds for reading from the consumer                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `CONNECTION TIMEOUT`               | *Any* except `JDBC`      | Timeout in seconds for connecting to a consumer                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `USE_HTTPS`                        | `AZURE`, `GCS`, `S3`     | Whether to connect to the storage consumer over HTTPS or not <br /> <br /> `true`: Use HTTPS *(default)* <br /> <br /> `false`: Use HTTP                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `USE_MANAGED_CREDENTIALS`          | `AZURE`, `GCS`, `S3`     | Whether to connect to the storage provider with consumer-managed credentials <br /> <br /> `AZURE`: Use the *Azure Instance Metadata Service (IMDS)* endpoint local to the Kinetica cluster to acquire credentials *(only for on-prem clusters deployed within Azure)* <br /> <br /> `GCS`: Satisfy the [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials) requirements for credentials, making sure any supporting server-side configuration (files, environment variables) is done on every node in the cluster *(only for on-prem clusters deployed within GCS)* <br /> <br /> `S3`: Use the [AWS Default Credential Provider Chain](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html) to acquire credentials, making sure any supporting server-side configuration (files, environment variables) is done on every node in the cluster *(only for on-prem clusters deployed within S3)* |
| `KAFKA_TOPIC_NAME`                 | `KAFKA`                  | Kafka topic to write to                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `JSON_FORMAT`                      | `HTTP`, `HTTPS`, `KAFKA` | The desired format of JSON encoded notifications message. <br /> <br /> `flat`: A single record is returned per message <br /> <br /> `nested`: Records are returned in an array per message                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `MAX_BATCH_SIZE`                   | `HTTP`, `HTTPS`, `KAFKA` | Maximum number of records per notification message                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `MAX_MESSAGE_SIZE`                 | `HTTP`, `HTTPS`, `KAFKA` | Maximum size in bytes of each notification message                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `CONTAINER NAME`                   | `AZURE`                  | Azure storage container name                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `SAS TOKEN`                        | `AZURE`                  | Azure storage account shared access signature token; this should be an account-level access token, not a container-level one                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `STORAGE ACCOUNT NAME`             | `AZURE`                  | Azure storage account name *(only used if* `TENANT ID` *is specified)*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `TENANT ID`                        | `AZURE`                  | Azure Active Directory tenant identifier                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `GCS_BUCKET_NAME`                  | `GCS`                    | Name of the GCS bucket to use as the data sink                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `GCS_PROJECT_ID`                   | `GCS`                    | Name of the Google Cloud project to use for request billing                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `GCS_SERVICE_ACCOUNT_KEYS`         | `GCS`                    | Text of the JSON key file containing the GCS private key                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `DELEGATION TOKEN`                 | `HDFS`                   | Optional Kerberos delegation token for *worker nodes*; if not specified, the token will be acquired from HDFS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `KERBEROS KEYTAB`                  | `HDFS`                   | Location of the Kerberos keytab file in [KiFS](/content/tools/kifs)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `USE KERBEROS`                     | `HDFS`                   | Whether to attempt Kerberos authentication to HDFS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `JDBC_DRIVER_CLASS_NAME`           | `JDBC`                   | JDBC driver class name *(optional, if the name is available in the* *JAR file's manifest)*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `JDBC_DRIVER_JAR_PATH`             | `JDBC`                   | [KiFS](/content/tools/kifs) path of the JDBC driver JAR file to use                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `BUCKET NAME`                      | `S3`                     | Amazon S3 bucket name                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `REGION`                           | `S3`                     | Amazon S3 region identifier                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `S3_AWS_ROLE_ARN`                  | `S3`                     | Amazon Resource Name (ARN) specifying the role                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `S3_ENCRYPTION_CUSTOMER_ALGORITHM` | `S3`                     | Algorithm used to encrypt/decrypt data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `S3_ENCRYPTION_CUSTOMER_KEY`       | `S3`                     | Key used to encrypt/decrypt data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `S3_ENCRYPTION_TYPE`               | `S3`                     | Server side encryption type                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `S3_KMS_KEY_ID`                    | `S3`                     | KMS key                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `S3_USE_VIRTUAL_ADDRESSING`        | `S3`                     | Whether to use virtual addressing when referencing the S3 sink <br /> <br /> `true`: The requests URI should be specified in virtual-hosted-style format where the bucket name is part of the domain name in the URL <br /> <br /> `false`: Use path-style URI for requests                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `S3_VERIFY_SSL`                    | `S3`                     | Whether to verify SSL connections <br /> <br /> `true`: Verify SSL connections *(default)* <br /> <br /> `false`: Don't verify SSL connections; for testing purposes, bypassing TLS errors, self-signed certificates, etc.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |

<a id="sql-create-data-sink-syntax" />

### Consumer-Specific Syntax

Several authentication schemes across multiple consumers are supported.

* [Azure](/content/sql/ddl#sql-create-data-sink-azure)
* [GCS](/content/sql/ddl#sql-create-data-sink-gcs)
* [HDFS](/content/sql/ddl#sql-create-data-sink-hdfs)
* [JDBC](/content/sql/ddl#sql-create-data-sink-jdbc)
* [Kafka](/content/sql/ddl#sql-create-data-sink-kafka)
* [Local (Kinetica)](/content/sql/ddl#sql-create-data-sink-local)
* [S3](/content/sql/ddl#sql-create-data-sink-s3)
* [Webhook](/content/sql/ddl#sql-create-data-sink-webhook)

<a id="sql-create-data-sink-azure" />

#### Azure

Syntax below, examples [here](/content/snippets/create-data-sinks#snippet-sql-create-data-sink-azure).

<CodeGroup>
  ```sql Credential theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = 'AZURE[://<host>]'
  WITH OPTIONS
  (
  	CREDENTIAL = '[<credential schema name>.]<credential name>',
  	CONTAINER NAME = '<azure container name>'
  )
  ```

  ```sql Managed Credentials theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = 'AZURE[://<host>]'
  WITH OPTIONS
  (
      USE_MANAGED_CREDENTIALS = true,
      STORAGE ACCOUNT NAME = '<azure storage account name>',
      CONTAINER NAME = '<azure container name>',
      TENANT ID = '<ad tenant id>'
  )
  ```
</CodeGroup>

<a id="sql-create-data-sink-gcs" />

#### GCS

Syntax below, examples [here](/content/snippets/create-data-sinks#snippet-sql-create-data-sink-gcs).

<CodeGroup>
  ```sql Credential theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = 'GCS[://<host>]'
  WITH OPTIONS
  (
  	CREDENTIAL = '[<credential schema name>.]<credential name>',
  	[GCS_PROJECT_ID = '<gcs project id>',]
  	GCS_BUCKET_NAME = '<gcs bucket name>'
  )
  ```

  ```sql Managed Credentials theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = 'GCS[://<host>]'
  WITH OPTIONS
  (
  	USE_MANAGED_CREDENTIALS = true,
  	[GCS_PROJECT_ID = '<gcs project id>',]
  	GCS_BUCKET_NAME = '<gcs bucket name>'
  )
  ```

  ```sql Public (No Auth) theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = 'GCS[://<host>]'
  WITH OPTIONS
  (
  	[GCS_PROJECT_ID = '<gcs project id>',]
  	GCS_BUCKET_NAME = '<gcs bucket name>'
  )
  ```

  ```sql JSON Key theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = 'GCS[://<host>]'
  WITH OPTIONS
  (
  	GCS_SERVICE_ACCOUNT_KEYS = '<gcs account json key text>',
  	[GCS_PROJECT_ID = '<gcs project id>',]
  	GCS_BUCKET_NAME = '<gcs bucket name>'
  )
  ```
</CodeGroup>

<a id="sql-create-data-sink-hdfs" />

#### HDFS

Syntax below, examples [here](/content/snippets/create-data-sinks#snippet-sql-create-data-sink-hdfs).

```sql Credential theme={null}
CREATE DATA SINK [<data sink schema name>.]<data sink name>
LOCATION = 'HDFS://<host>:<port>'
WITH OPTIONS (CREDENTIAL = '[<credential schema name>.]<credential name>')
```

<a id="sql-create-data-sink-jdbc" />

#### JDBC

Syntax below, examples [here](/content/snippets/create-data-sinks#snippet-sql-create-data-sink-jdbc).

<CodeGroup>
  ```sql Credential theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = '<jdbc url>'
  WITH OPTIONS
  (
  	[JDBC_DRIVER_CLASS_NAME = '<jdbc driver class full path>',]
  	[JDBC_DRIVER_JAR_PATH = 'kifs://<jdbc driver jar path>',]
  	CREDENTIAL = '[<credential schema name>.]<credential name>'
  )
  ```

  ```sql Password in URL theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = '<jdbc url with username/password>'
  ```
</CodeGroup>

<a id="sql-create-data-sink-kafka" />

#### Kafka

Syntax below, examples [here](/content/snippets/create-data-sinks#snippet-sql-create-data-sink-kafka).

<CodeGroup>
  ```sql Credential theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = 'kafka://<host>[:<port>]'
  WITH OPTIONS
  (
  	CREDENTIAL = '[<credential schema name>.]<credential name>',
  	KAFKA_TOPIC_NAME = '<kafka topic name>'
  )
  ```

  ```sql Public (No Auth) theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = 'kafka://<host>[:<port>]'
  WITH OPTIONS (KAFKA_TOPIC_NAME = '<kafka topic name>')
  ```
</CodeGroup>

<a id="sql-create-data-sink-local" />

#### Local (Kinetica)

Syntax below, examples [here](/content/snippets/create-data-sinks#snippet-sql-create-data-sink-local).

```sql User Auth theme={null}
CREATE DATA SINK [<data sink schema name>.]<data sink name>
LOCATION = 'TABLE://[<table schema name>.]<table name>'
```

<a id="sql-create-data-sink-s3" />

#### S3

Syntax below, examples [here](/content/snippets/create-data-sinks#snippet-sql-create-data-sink-s3).

<CodeGroup>
  ```sql Credential theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = 'S3[://<host>]'
  WITH OPTIONS
  (
      CREDENTIAL = '[<credential schema name>.]<credential name>',
      BUCKET NAME = '<aws bucket name>',
      REGION = '<aws region>'
  )
  ```

  ```sql Managed Credentials theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = 'S3[://<host>]'
  WITH OPTIONS
  (
      USE_MANAGED_CREDENTIALS = true,
      BUCKET NAME = '<aws bucket name>',
      REGION = '<aws region>'
  )
  ```

  ```sql Public (No Auth) theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = 'S3[://<host>]'
  WITH OPTIONS
  (
      BUCKET NAME = '<aws bucket name>',
      REGION = '<aws region>'
  )
  ```
</CodeGroup>

<a id="sql-create-data-sink-webhook" />

#### Webhook

Syntax below, examples [here](/content/snippets/create-data-sinks#snippet-sql-create-data-sink-webhook).

<CodeGroup>
  ```sql Credential w/ HTTPS theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = 'https://<host>[:<port>]'
  WITH OPTIONS (CREDENTIAL = '[<credential schema name>.]<credential name>')
  ```

  ```sql HTTP theme={null}
  CREATE DATA SINK [<data sink schema name>.]<data sink name>
  LOCATION = 'http://<host>[:<port>]'
  ```
</CodeGroup>

<a id="sql-alter-data-sink" />

## ALTER DATA SINK

Alters the connection parameters of an existing
[data sink](/content/sql/ddl#sql-create-data-sink).

```sql title="ALTER DATA SINK Syntax" theme={null}
ALTER [EXTERNAL] DATA SINK [<data sink schema name>.]<data sink name>
SET PROPERTY
    <property name> = '<property value>'[,...]
```

<Info>
  Kafka *data sinks* will be validated upon creation, by default, and
  will fail to be created if an authorized connection cannot be established.
</Info>

### Parameters

<AccordionGroup>
  <Accordion title="EXTERNAL" id="external-7" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-28" defaultOpen>
    Name of the *schema* containing the *data sink* to alter
  </Accordion>

  <Accordion title="<data sink name>" id="<data-sink-name>-2" defaultOpen>
    Name of the *data sink* to alter
  </Accordion>

  <Accordion title="SET PROPERTY" id="set-property-3" defaultOpen>
    Indicator that a comma-delimited list of alterations to make will follow.

    See [Set Properties](/content/sql/ddl#sql-alter-data-sink-prop) for the complete list of properties.
  </Accordion>
</AccordionGroup>

### Examples

To alter a *data sink*, `kin_dsink`, updating the timeouts:

```sql ALTER DATA SINK Example theme={null}
ALTER DATA SINK kin_dsink
SET PROPERTY
    CONNECTION TIMEOUT = '10',
    WAIT TIMEOUT = '10'
```

<a id="sql-alter-data-sink-prop" />

### Set Properties

All *data sink* properties can be altered via [ALTER DATA SINK](/content/sql/ddl#sql-alter-data-sink).
The following are the property names and descriptions to use when performing an
alteration.

| Option                             | Consumer                 | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `CREDENTIAL`                       | *Any*                    | [Credential](/content/sql/ddl#sql-create-credential) object to use to authenticate to the remote consumer                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `LOCATION`                         | *Any*                    | Location of the *data sink*; see [Consumer-Specific Syntax](/content/sql/ddl#sql-create-data-sink-syntax) for details                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `VALIDATE`                         | *Any*                    | Whether to test the connection to the *data sink* upon creation; if `TRUE` *(default)*, the creation of a *data sink* that cannot be connected to will fail; if `FALSE`, the *data sink* will be created regardless of connectivity                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `WAIT TIMEOUT`                     | *Any* except `JDBC`      | Timeout in seconds for reading from the consumer                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `CONNECTION TIMEOUT`               | *Any* except `JDBC`      | Timeout in seconds for connecting to a consumer                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `USE_HTTPS`                        | `AZURE`, `GCS`, `S3`     | Whether to connect to the storage provider over HTTPS or not <br /> <br /> `true`: Use HTTPS *(default)* <br /> <br /> `false`: Use HTTP                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `USE_MANAGED_CREDENTIALS`          | `AZURE`, `GCS`, `S3`     | Whether to connect to the storage provider with consumer-managed credentials <br /> <br /> `AZURE`: Use the *Azure Instance Metadata Service (IMDS)* endpoint local to the Kinetica cluster to acquire credentials *(only for on-prem clusters deployed within Azure)* <br /> <br /> `GCS`: Satisfy the [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials) requirements for credentials, making sure any supporting server-side configuration (files, environment variables) is done on every node in the cluster *(only for on-prem clusters deployed within GCS)* <br /> <br /> `S3`: Use the [AWS Default Credential Provider Chain](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html) to acquire credentials, making sure any supporting server-side configuration (files, environment variables) is done on every node in the cluster *(only for on-prem clusters deployed within S3)* |
| `KAFKA_TOPIC_NAME`                 | `KAFKA`                  | Kafka topic to write to                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `JSON_FORMAT`                      | `HTTP`, `HTTPS`, `KAFKA` | The desired format of JSON encoded notifications message. <br /> <br /> `flat`: A single record is returned per message <br /> <br /> `nested`: Records are returned in an array per message                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `MAX_BATCH_SIZE`                   | `HTTP`, `HTTPS`, `KAFKA` | Maximum number of records per notification message                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `MAX_MESSAGE_SIZE`                 | `HTTP`, `HTTPS`, `KAFKA` | Maximum size in bytes of each notification message                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `CONTAINER NAME`                   | `AZURE`                  | Azure storage container name                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `SAS TOKEN`                        | `AZURE`                  | Azure storage account shared access signature token; this should be an account-level access token, not a container-level one                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `STORAGE ACCOUNT NAME`             | `AZURE`                  | Azure storage account name *(only used if* `TENANT ID` *is specified)*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `TENANT ID`                        | `AZURE`                  | Azure Active Directory tenant identifier                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `GCS_BUCKET_NAME`                  | `GCS`                    | Name of the GCS bucket to use as the data sink                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `GCS_PROJECT_ID`                   | `GCS`                    | Name of the Google Cloud project to use for request billing                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `GCS_SERVICE_ACCOUNT_KEYS`         | `GCS`                    | Text of the JSON key file containing the GCS private key                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `DELEGATION TOKEN`                 | `HDFS`                   | Optional Kerberos delegation token for *worker nodes*; if not specified, the token will be acquired from HDFS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `KERBEROS KEYTAB`                  | `HDFS`                   | Location of the Kerberos keytab file in [KiFS](/content/tools/kifs)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `USE KERBEROS`                     | `HDFS`                   | Whether to attempt Kerberos authentication to HDFS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `JDBC_DRIVER_CLASS_NAME`           | `JDBC`                   | JDBC driver class name *(optional, if the name is available in the* *JAR file's manifest)*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `JDBC_DRIVER_JAR_PATH`             | `JDBC`                   | [KiFS](/content/tools/kifs) path of the JDBC driver JAR file to use                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `BUCKET NAME`                      | `S3`                     | Amazon S3 bucket name                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `REGION`                           | `S3`                     | Amazon S3 region identifier                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `S3_AWS_ROLE_ARN`                  | `S3`                     | Amazon Resource Name (ARN) specifying the role                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `S3_ENCRYPTION_CUSTOMER_ALGORITHM` | `S3`                     | Algorithm used to encrypt/decrypt data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `S3_ENCRYPTION_CUSTOMER_KEY`       | `S3`                     | Key used to encrypt/decrypt data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `S3_ENCRYPTION_TYPE`               | `S3`                     | Server side encryption type                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `S3_KMS_KEY_ID`                    | `S3`                     | KMS key                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `S3_USE_VIRTUAL_ADDRESSING`        | `S3`                     | Whether to use virtual addressing when referencing the S3 sink <br /> <br /> `true`: The requests URI should be specified in virtual-hosted-style format where the bucket name is part of the domain name in the URL <br /> <br /> `false`: Use path-style URI for requests                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `S3_VERIFY_SSL`                    | `S3`                     | Whether to verify SSL connections <br /> <br /> `true`: Verify SSL connections *(default)* <br /> <br /> `false`: Don't verify SSL connections; for testing purposes, bypassing TLS errors, self-signed certificates, etc.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |

<a id="sql-drop-data-sink" />

## DROP DATA SINK

Removes an existing [data sink](/content/sql/ddl#sql-create-data-sink).

```sql title="DROP DATA SINK Syntax" theme={null}
DROP [EXTERNAL] DATA SINK [<schema name>.]<data sink name>
```

<Info>
  Any [streams](/content/sql/ddl#sql-create-stream) that depend on a given
  *data sink* must be dropped before it can be dropped.
</Info>

### Parameters

<AccordionGroup>
  <Accordion title="EXTERNAL" id="external-8" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-29" defaultOpen>
    Name of the *schema* containing the *data sink* to remove
  </Accordion>

  <Accordion title="<data sink name>" id="<data-sink-name>-3" defaultOpen>
    Name of the *data sink* to remove
  </Accordion>
</AccordionGroup>

### Examples

To drop a *data sink*, `kin_dsink`:

```sql DROP DATA SINK Example theme={null}
DROP DATA SINK kin_dsink
```

<a id="sql-show-data-sink" />

## SHOW DATA SINK

Outputs the DDL statement required to reconstruct the given
[data sink](/content/sql/ddl#sql-create-data-sink).

```sql title="SHOW DATA SINK Syntax" theme={null}
SHOW [EXTERNAL] DATA SINK < [<schema name>.]<data sink name> | * >
```

<Info>
  The response to `SHOW DATA SINK` is a single-column result set
  with the DDL statement as the value in the `DDL` column.
</Info>

### Parameters

<AccordionGroup>
  <Accordion title="EXTERNAL" id="external-9" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-30" defaultOpen>
    Name of the *schema* containing the *data sink* to show
  </Accordion>

  <Accordion title="<data sink name>" id="<data-sink-name>-4" defaultOpen>
    Name of the *data sink* for which the DDL will be output; use `*` instead of
    *schema*/*data sink* name to output the DDL of all *data sinks*
  </Accordion>
</AccordionGroup>

### Examples

To output the DDL for a *data sink*, `kin_dsink`:

```sql SHOW DATA SINK Example theme={null}
SHOW DATA SINK kin_dsink
```

To output the DDL for all *data sinks*:

```sql SHOW DATA SINK (All Data Sinks) Example theme={null}
SHOW DATA SINK *
```

<a id="sql-desc-data-sink" />

## DESCRIBE DATA SINK

Outputs the configuration of an existing
[data sink](/content/sql/ddl#sql-create-data-sink).

```sql title="SHOW DATA SINK Syntax" theme={null}
DESC[RIBE] [EXTERNAL] DATA SINK < [<schema name>.]<data sink name> | * >
```

### Parameters

<AccordionGroup>
  <Accordion title="EXTERNAL" id="external-10" defaultOpen>
    Optional keyword for clarity
  </Accordion>

  <Accordion title="<schema name>" id="<schema-name>-31" defaultOpen>
    Name of the *schema* containing the *data sink* to describe
  </Accordion>

  <Accordion title="<data sink name>" id="<data-sink-name>-5" defaultOpen>
    Name of the *data sink* whose configuration will be output; use `*` instead of
    *schema*/*data sink* name to output the configuration of all *data sinks*
  </Accordion>
</AccordionGroup>

### Response

The response to `DESCRIBE DATA SINK` is a three-column result set:

| Output Column           | Description                              |
| ----------------------- | ---------------------------------------- |
| `DATA_SINK`             | Name of the *data sink*                  |
| `STORAGE_PROVIDER_TYPE` | Keyword identifying *data sink* consumer |
| `ADDITIONAL_INFO`       | *Data sink* configuration                |

### Examples

To show the configuration for a *data sink*, `kin_dsink`:

```sql DESCRIBE DATA SINK Example theme={null}
DESC DATA SINK kin_dsink
```

To show the configuration for all *data sinks*:

```sql DESCRIBE DATA SINK (All Data Sinks) Example theme={null}
DESC DATA SINK *
```

<a id="sql-create-stream" />

## CREATE STREAM

Creates a new data *stream* (natively, a
[table monitor](/content/concepts/table_monitors)), which publishes changes
in a given table to a target.

```sql title="CREATE STREAM Syntax" theme={null}
CREATE STREAM [<stream schema name>.]<stream name>
ON
<
    [TABLE] [<table schema name>.]<table name>
    |
    [QUERY] (<query>)
>
[
    REFRESH
    <
        ON CHANGE |
        EVERY <number> <SECOND[S] | MINUTE[S] | HOUR[S] | DAY[S]> [STARTING AT '<YYYY-MM-DD [HH:MM[:SS]]>']
    >
]
[WHERE <filter expression>]
WITH OPTIONS
(
    < DATASINK_NAME = '<data sink name>' | DESTINATION = '<destination>' >,
    <option name> = '<option value>'[,...]
)
```

The monitored table can be one of:

* a [table](/content/sql/ddl#sql-create-table)
  ([external tables](/content/sql/ddl#sql-create-ext-table) not supported)
* a [materialized view](/content/sql/ddl#sql-create-materialized-view) (insert monitoring only)

The target can be one of:

* an external Apache Kafka broker
* an external webhook
* a local database table

By default, a *stream* will publish inserted records to the target.  A *stream*
can alternatively be configured to monitor for updates or deletes and publish
the corresponding record counts.  *Streams* that monitor for inserts can have an
expression applied to only have specific inserts of interest published.

An existing [data sink](/content/sql/ddl#sql-create-data-sink) can be referenced in
creating a *stream*, as the target of the streamed data.  Only local tables or
unauthenticated external targets may be used if not using an existing
*data sink*; however, in these cases, a *data sink* will automatically be
created to support the *stream*.

When the source *table* of a *stream* is altered or dropped, the *stream* will
also be dropped.

### Parameters

<AccordionGroup>
  <Accordion title="<stream schema name>" id="<stream-schema-name>" defaultOpen>
    Name of the *schema* that will contain the created *stream*; if no *schema* is specified, the
    *stream* will be created in the user's [default schema](/content/concepts/schemas#schema-default)
  </Accordion>

  <Accordion title="<stream name>" id="<stream-name>" defaultOpen>
    Name of the *stream* to create; must adhere to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria)
  </Accordion>

  <Accordion title="TABLE" id="table-4" defaultOpen>
    Optional keyword for clarity, in creating a *stream* on a *table*.
  </Accordion>

  <Accordion title="<table schema name>" id="<table-schema-name>" defaultOpen>
    Name of the *schema* containing the *table* or *materialized view* to monitor.
  </Accordion>

  <Accordion title="<table name>" id="<table-name>-6" defaultOpen>
    Name of the *table* or *materialized view* to monitor for changes.
  </Accordion>

  <Accordion title="QUERY" id="query" defaultOpen>
    Optional keyword for clarity, in creating a *stream* on a join.
  </Accordion>

  <Accordion title="<query>" id="<query>" defaultOpen>
    Join query to which the *stream* will be applied, using the following form:

    \{\{\< code "sql" "linenos=true" "Query Syntax" >}}
    SELECT \*
    FROM \<delta\_table> dt
    LEFT SEMI JOIN \<lookup\_table> lt
    ON \<join\_clause>
    \{\{\< /code >}}

    Here, `<delta_table>` is the data table being monitored and `<lookup_table>` contains the
    criteria for whether a `<delta_table>` record should be streamed or not, as determined by
    the given `<join_clause>`.

    <Info>
      The marked *delta table* must be a regular table--it cannot be any of the
      following:

      * [external table](/content/sql/ddl#sql-create-ext-table)
      * [filter view](/content/concepts/filtered_views)
      * [join view](/content/concepts/joins)
      * [logical view](/content/sql/ddl#sql-create-view)
      * [materialized view](/content/sql/ddl#sql-create-materialized-view)

      The join must also meet [sharding](/content/concepts/tables#sharding) requirements for joins--either both
      tables need to have [shard keys](/content/concepts/tables#shard-key) on their equality-based joined
      columns, or at least one of the tables needs to be [replicated](/content/concepts/tables#replicated).

      See [CREATE TABLE](/content/sql/ddl#sql-create-table) for syntax for creating a *replicated* table or a
      *sharded table* with a *shard key* column.
    </Info>

    See below for a table-driven geofence example using a query-based *stream*.
  </Accordion>

  <Accordion title="REFRESH" id="refresh-2" defaultOpen>
    Specifies the reporting scheme for monitored changes.   The following schemes are available:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Constant</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>ON CHANGE</code></td>
            <td>Will cause notifications to be streamed any time a record is added, modified, or deleted from the monitored table</td>
          </tr>

          <tr>
            <td><code>EVERY</code></td>
            <td>Allows specification of an interval in seconds, minutes, hours, or days, with the optional specification of a starting time at which the first monitor interval will run; if no start time is specified, the default will be an interval's worth of time from the point at which the stream was created</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="<filter expression>" id="<filter-expression>" defaultOpen>
    Boolean expression that can be used to monitor for only a specific set of inserts.
  </Accordion>

  <Accordion title="WITH OPTIONS" id="with-options-8" defaultOpen>
    Indicator that a comma-delimited list of configuration option/value assignments will follow.
    See [Options](/content/sql/ddl#sql-stream-opts) for the full list of options.

    <Info>
      One of either `DATASINK_NAME` or `DESTINATION` is required.
    </Info>
  </Accordion>
</AccordionGroup>

### Examples

To create a *stream*, `kin_stream`, that publishes inserts into the
`order_stream` table of orders over \$10,000 via the `kin_dsink` *data sink*:

```sql CREATE STREAM Example theme={null}
CREATE STREAM example.kin_stream ON example.order_stream
WHERE cost > 10000.00
WITH OPTIONS (DATASINK_NAME = 'example.kin_dsink')
```

To create a *stream*, `kin_stream`, that publishes inserts into the
`order_stream` table of orders, placed within a given string-literal geofence,
via the `kin_dsink` *data sink*:

```sql CREATE STREAM Single Geometry Geofence Example theme={null}
CREATE STREAM example.kin_stream ON example.order_stream
REFRESH ON CHANGE
WHERE STXY_INTERSECTS(lon, lat, 'POLYGON((
    -108.97203757374318 40.945055425026034,
    -101.72106101124318 40.945055425026034,
    -101.72106101124318 36.98324941198095,
    -108.97203757374318 36.98324941198095,
    -108.97203757374318 40.945055425026034
    ))')
WITH OPTIONS (DATASINK_NAME = 'example.kin_dsink')
```

To create a *stream*, `kin_stream`, that publishes inserts into the
`order_stream` table of orders, placed within a table-driven geofence defined
in `order_location`, via the `kin_dsink` *data sink*; noting that the
`order_location` table in this example is
[replicated](/content/concepts/tables#replicated):

```sql CREATE STREAM Table-Driven Geofence Example theme={null}
CREATE STREAM example.kin_stream
ON QUERY
(
	SELECT *
	FROM example.order_stream os
	LEFT SEMI JOIN example.order_location ol
		ON STXY_INTERSECTS(os.lon, os.lat, ol.geom)
)
REFRESH ON CHANGE
WITH OPTIONS (DATASINK_NAME = 'example.kin_dsink')
```

To create a *stream*, `kin_stream`, that inserts into the local
`order_target` table any orders over \$10,000 inserted into the
`order_stream` table:

```sql CREATE STREAM to Local Table Example theme={null}
CREATE STREAM example.kin_stream ON example.order_stream
WHERE cost > 10000.00
WITH OPTIONS (DESTINATION = 'TABLE://example.order_target')
```

<a id="sql-stream-opts" />

### Options

| Option                            | Consumer               | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| --------------------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DATASINK_NAME`                   | *Any*                  | [Data sink](/content/sql/ddl#sql-create-data-sink) object to use to identify the consumer of this stream; mutually exclusive with `destination`                                                                                                                                                                                                                                                                                                                                                         |
| `DESTINATION`                     | *Any*                  | Location of the target when not using a *data sink*; the URL of the consumer to connect to in this format: <br /> <br /> `<consumer>://<target>[:<port>]` <br /> <br /> Supported consumers include: <br /> <br /> `http`: Unsecured webhook <br /> <br /> `https`: Secured webhook <br /> <br /> `kafka`: Apache Kafka broker <br /> <br /> `table`: Local Kinetica table, where `target` is the name of the target table in the following format: <br /> <br /> `[<schema name>.]<table name>` <br /> |
| `EVENT`                           | *Any*                  | Specifies the type of event to monitor <br /> <br /> `insert`: *(default)* Monitor inserts and publish them to the target <br /> <br /> `update`: Monitor updates and publish their counts to the target <br /> <br /> `delete`: Monitor deletes and publish their counts to the target                                                                                                                                                                                                                 |
| `INCREASING_COLUMN`               | *Any*                  | Column of the monitored table that contains ever-increasing values for new data; e.g., a timestamp or sequence ID column <br /> <Tip> If such a column can be identified, the performance of the *stream* will improve. </Tip>                                                                                                                                                                                                                                                                          |
| `MAX_CONSECUTIVE_FAILURES`        | *Any*                  | Maximum number of failed notification attempts before automatically suspending the the *stream*.  The default, `-1`, disables auto-suspension.                                                                                                                                                                                                                                                                                                                                                          |
| `FAILED_NOTIFICATIONS_TABLE_NAME` | `http` `https` `kafka` | Name of the table to which failed *stream* notifications are written and from which they are replayed when the *stream* is re-enabled from a suspended state. The default is no table for storing/replaying failed *stream* notifications.                                                                                                                                                                                                                                                              |
| `KAFKA_TOPIC_NAME`                | `kafka`                | Kafka topic to write to, if the target is a Kafka broker                                                                                                                                                                                                                                                                                                                                                                                                                                                |

<a id="sql-create-stream-consumers" />

### Consumer-Specific Syntax

Several configurations across multiple consumers are supported.

<CodeGroup>
  ```sql Data Sink theme={null}
  CREATE STREAM [<stream schema name>.]<stream name>
  ON [TABLE] [<table schema name>.]<table name>
  [WHERE <filter expression>]
  WITH OPTIONS (DATASINK_NAME = '[<data sink schema name>.]<data sink name>')
  ```

  ```sql HTTP theme={null}
  CREATE STREAM [<stream schema name>.]<stream name>
  ON [TABLE] [<table schema name>.]<table name>
  [WHERE <filter expression>]
  WITH OPTIONS (DESTINATION = 'http://<host>[:<port>]')
  ```

  ```sql HTTPS theme={null}
  CREATE STREAM [<stream schema name>.]<stream name>
  ON [TABLE] [<table schema name>.]<table name>
  [WHERE <filter expression>]
  WITH OPTIONS (DESTINATION = 'https://<host>[:<port>]')
  ```

  ```sql Kafka (No auth) theme={null}
  CREATE STREAM [<stream schema name>.]<stream name>
  ON [TABLE] [<table schema name>.]<table name>
  [WHERE <filter expression>]
  WITH OPTIONS
  (
  	DESTINATION = 'kafka://<host>:<port>',
  	KAFKA_TOPIC_NAME = '<kafka topic name>'
  )
  ```

  ```sql Local Table theme={null}
  CREATE STREAM [<stream schema name>.]<stream name>
  ON [TABLE] [<source table schema name>.]<source table name>
  [WHERE <filter expression>]
  WITH OPTIONS (DESTINATION = 'table://[<target table schema name>.]<target table name>')
  ```
</CodeGroup>

<a id="sql-drop-stream" />

## DROP STREAM

Removes an existing [stream](/content/sql/ddl#sql-create-stream).

```sql title="DROP STREAM Syntax" theme={null}
DROP STREAM [<schema name>.]<stream name>
```

### Parameters

<AccordionGroup>
  <Accordion title="<schema name>" id="<schema-name>-32" defaultOpen>
    Name of the *schema* containing the *stream* to remove
  </Accordion>

  <Accordion title="<stream name>" id="<stream-name>-2" defaultOpen>
    Name of the *stream* to remove
  </Accordion>
</AccordionGroup>

### Examples

To drop a *stream*, `kin_stream`:

```sql DROP STREAM Example theme={null}
DROP STREAM example.kin_stream
```

<a id="sql-show-stream" />

## SHOW STREAM

Outputs the DDL statement required to reconstruct one or more existing
[streams](/content/sql/ddl#sql-create-stream).

```sql title="SHOW STREAM Syntax" theme={null}
SHOW STREAM < [<schema name>.]<stream name> | <schema name>.* | * >
```

Listing options:

* `[<schema name>.]<stream name>` - output the DDL statement of the given
  *stream*
* `<schema name>.*` - output the DDL statements of all *streams* under the
  given *schema*
* `*` - output the DDL statements of all *streams*

<Info>
  The response to `SHOW STREAM` is a single-column result set
  with the DDL statement as the value in the `DDL` column.
</Info>

### Parameters

<AccordionGroup>
  <Accordion title="<schema name>" id="<schema-name>-33" defaultOpen>
    Name of the *schema* containing the *stream(s)* to show
  </Accordion>

  <Accordion title="<stream name>" id="<stream-name>-3" defaultOpen>
    Name of the *stream* to show
  </Accordion>
</AccordionGroup>

### Examples

To output the DDL for a *stream*, `kin_stream`:

```sql SHOW STREAM Example theme={null}
SHOW STREAM example.kin_stream
```

<a id="sql-desc-stream" />

## DESCRIBE STREAM

Outputs the configuration of one or more existing
[streams](/content/sql/ddl#sql-create-stream).

```sql title="SHOW STREAM Syntax" theme={null}
DESC[RIBE] STREAM < [<schema name>.]<stream name> | <schema name>.* | * >
```

Listing options:

* `[<schema name>.]<stream name>` - output the configuration of the given
  *stream*
* `<schema name>.*` - output the configuration of all *streams* under the
  given *schema*
* `*` - output the configuration of all *streams*

### Parameters

<AccordionGroup>
  <Accordion title="<schema name>" id="<schema-name>-34" defaultOpen>
    Name of the *schema* containing the *stream(s)* to describe
  </Accordion>

  <Accordion title="<stream name>" id="<stream-name>-4" defaultOpen>
    Name of the *stream* to describe
  </Accordion>
</AccordionGroup>

### Response

The response to `DESCRIBE STREAM` is a nine-column result set:

| Output Column                     | Description                                                                                               |
| --------------------------------- | --------------------------------------------------------------------------------------------------------- |
| `MONITOR_ID`                      | Unique name or topic ID for the *stream*                                                                  |
| `TABLE_NAME`                      | Name of the table being monitored                                                                         |
| `EVENT`                           | Table data event that triggers streamed content                                                           |
| `INCREASING_COLUMN`               | Column in table being monitored that contains ever-increasing data values                                 |
| `FILTER_EXPRESSION`               | Filter used to monitor only data of interest                                                              |
| `MAX_CONSECUTIVE_FAILURES`        | Maximum number of failed notification attempts before suspending the *stream*; `-1` disables auto-suspend |
| `FAILED_NOTIFICATIONS_TABLE_NAME` | Name of the table to which failed *stream* notifications are written and replayed when re-enabled         |
| `DATASINK_NAME`                   | Name of the *data sink* associated with the consumer                                                      |
| `STATUS`                          | Whether the stream is enabled or suspended                                                                |

### Examples

To show the configuration for a *stream*, `kin_stream`:

```sql DESCRIBE STREAM Example theme={null}
DESC STREAM example.kin_stream
```

## DESCRIBE

Lists the contained *tables* and *views* of a given *schema*, or lists the
columns and column types & properties for a given *table* or *view*.

```sql title="DESCRIBE Schema Syntax" theme={null}
DESC[RIBE] <schema name>
```

```sql title="DESCRIBE Table Syntax" theme={null}
DESC[RIBE] [<schema name>.]<table/view name>
```

### Examples

To describe the tables contained in the `demo` schema, into
which demo data is usually downloaded:

```sql DESCRIBE Schema Example theme={null}
DESC demo
```

```sql DESCRIBE Schema Output theme={null}
+------------+
| Set_name   |
+------------+
| stocks     |
| nyctaxi    |
| flights    |
+------------+
```

To describe the example table created in the [CREATE TABLE](/content/sql/ddl#sql-create-table) section:

```sql DESCRIBE Table Example theme={null}
DESC example.various_types
```

```sql DESCRIBE Table Output theme={null}
+-----------+--------+------------+-----------------------------------+
| Col_num   | Name   | Null?      | Type                              |
+-----------+--------+------------+-----------------------------------+
| 0         | i      | NOT NULL   | INTEGER (primary_key)             |
| 1         | bi     | NOT NULL   | BIGINT (primary_key, shard_key)   |
| 2         | b      |            | BOOLEAN                           |
| 3         | ub     |            | UNSIGNED BIGINT                   |
| 4         | r      |            | REAL                              |
| 5         | d      |            | DOUBLE                            |
| 6         | s      |            | VARCHAR (text_search)             |
| 7         | c      |            | VARCHAR (32, dict)                |
| 8         | p      |            | VARCHAR (256, text_search)        |
| 9         | ip     |            | IPV4                              |
| 10        | ui     |            | UUID (init_with_uuid)             |
| 11        | ts     |            | TIMESTAMP                         |
| 12        | td     |            | DATE                              |
| 13        | tt     |            | TIME                              |
| 14        | dt     |            | DATETIME (init_with_now)          |
| 15        | dc     |            | DECIMAL (28, 0)                   |
| 16        | dc8    |            | DECIMAL (18, 4)                   |
| 17        | dc12   |            | DECIMAL (27, 18)                  |
| 18        | n      |            | DECIMAL (18, 4)                   |
| 19        | byt    |            | BLOB                              |
| 20        | w      |            | GEOMETRY                          |
| 21        | j      |            | JSON                              |
| 22        | v      |            | VECTOR (10)                       |
| 23        | ai     |            | INTEGER[3]                        |
+-----------+--------+------------+-----------------------------------+
```

<a id="sql-comment" />

## Comments

*Comments*, text-based tags, can be applied to a variety of object types.

Normally, *comments* are applied to objects after the object is created;
however, *comments* can also be applied in-line to table columns within a
[CREATE TABLE](/content/sql/ddl#sql-create-table) or [CREATE EXTERNAL TABLE](/content/sql/ddl#sql-create-ext-table)
statement.

```sql title="COMMENT Syntax" theme={null}
COMMENT ON <object type> <object name> IS '<comment text>';
```

### Parameters

<AccordionGroup>
  <Accordion title="<object type>" id="<object-type>" defaultOpen>
    Specifies the type of object to which the *comment* will be applied.  The following types are
    supported:

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Type</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>SCHEMA</code></td>
            <td>Apply a [schema-level](/content/sql/ddl#sql-create-schema) comment; can be viewed in the <code>ki\_catalog.ki\_schemas</code> [Kinetica catalog table](/content/catalogs/kinetica)</td>
          </tr>

          <tr>
            <td><code>TABLE</code></td>
            <td>Apply a [table-level](/content/sql/ddl#sql-create-table) comment; can be viewed in the <code>ki\_catalog.ki\_objects</code> [Kinetica catalog table](/content/catalogs/kinetica)</td>
          </tr>

          <tr>
            <td><code>VIEW</code></td>
            <td>Apply a [view-level](/content/sql/ddl#sql-create-view) comment; can be viewed in the <code>ki\_catalog.ki\_objects</code> [Kinetica catalog table](/content/catalogs/kinetica)</td>
          </tr>

          <tr>
            <td><code>COLUMN</code></td>
            <td>Apply a [column-level](/content/sql/ddl#sql-create-table) comment; can be viewed in the <code>ki\_catalog.ki\_columns</code> [Kinetica catalog table](/content/catalogs/kinetica)</td>
          </tr>

          <tr>
            <td><code>PROCEDURE</code></td>
            <td>Apply a [procedure-level](/content/sql/procedure) comment; can be viewed in the <code>ki\_catalog.ki\_objects</code> [Kinetica catalog table](/content/catalogs/kinetica)</td>
          </tr>

          <tr>
            <td><code>USER</code></td>
            <td>Apply a [user-level](/content/sql/security#sql-security-user-mgmt) comment; can be viewed in the <code>ki\_catalog.ki\_users\_and\_roles</code> [Kinetica catalog table](/content/catalogs/kinetica)</td>
          </tr>

          <tr>
            <td><code>ROLE</code></td>
            <td>Apply a [role-level](/content/sql/security#sql-security-role-mgmt) comment; can be viewed in the <code>ki\_catalog.ki\_users\_and\_roles</code> [Kinetica catalog table](/content/catalogs/kinetica)</td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>

  <Accordion title="<object name>" id="<object-name>" defaultOpen>
    Name of the object to which the *comment* will be applied; must adhere to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria)
  </Accordion>

  <Accordion title="<comment text>" id="<comment-text>" defaultOpen>
    Text of the *comment* to apply.
  </Accordion>
</AccordionGroup>

### Examples

For example, to apply a *comment* to a column in-line with the containing table
creation:

```sql In-Line Column Comment Example theme={null}
CREATE TABLE comment_schema.comment_table_inline
(
	id INT COMMENT 'I''m an in-line table column-level comment',
	name VARCHAR(32)
)
```

To apply a *comment* to a column after the containing table is created:

```sql Post-Creation Column Comment Example theme={null}
COMMENT ON COLUMN comment_schema.comment_table_inline.name IS 'I''m a post-creation table column-level comment'
```

### List Comments

To list the *comments* for users & roles:

```sql List User/Role Comments theme={null}
SELECT name, comments
FROM ki_users_and_roles
```

To list the *comments* for schemas:

```sql List Schema Comments theme={null}
SELECT schema_name, comments
FROM ki_schemas
```

To list the *comments* for tables, views, & SQL procedures:

```sql List Table/View/Procedure Comments theme={null}
SELECT obj_kind, object_name, comments
FROM ki_objects
```

To list the *comments* for columns:

```sql List Column Comments theme={null}
SELECT schema_name, table_name, column_name, comments
FROM ki_columns
```

To show the *comments* for columns within the context of the containing table,
use [SHOW TABLE](/content/sql/ddl#sql-show-table) on the table containing the columns.
