---
schema_version: "1"
id: 16d959204500e70fec2f0e6018181c07c1ffb3b64a47f56911df0dfd2ee67f6f
title: ALTER TABLE
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-query-guide/references/data-cloud-sql-reference/tableau-sql-commands/alter-table.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/alter-table.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: e9a3933f964b6d34b0ea15cf0e83834900d8cd311cc74e6eb08301c7448a27c3
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# ALTER TABLE

**Applies to:** ❌ Data 360 SQL ✅ Tableau Hyper API

Change the definition of a table.

## Syntax

```sql
ALTER TABLE [IF EXISTS] <name> RENAME TO <new_name>;
ALTER TABLE [IF EXISTS] <name> RENAME [COLUMN] <column_name> TO <new_name>;

ALTER TABLE [IF EXISTS] <name>
  ADD [COLUMN] [IF NOT EXISTS] <column_name> <data_type>
  [COLLATE <collation>]
  [<column_constraint>] [...];

ALTER TABLE [IF EXISTS] DROP [COLUMN] [IF EXISTS] <column_name>

ALTER TABLE [IF EXISTS] <name> ADD <table_constraint>;
```

where `column_constraint` is:

```sql
{ NOT NULL | NULL | DEFAULT default_expr }
```

and `table_constraint` is as described in [CREATE TABLE](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/create-table.md).

## Description

`ALTER TABLE` changes the definition of an existing table. Hyper
currently only supports the following changes:

- `RENAME`

  - : The `RENAME` forms change the name of a table, the name of an
    individual column in a table, or the name of a constraint of the
    table. There is no effect on the stored data.

- `ADD COLUMN [ IF NOT EXISTS ]`

  - : This form adds a new column to the table, using the same syntax as
    [CREATE TABLE](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/create-table.md). If `IF NOT EXISTS` is specified and a
    column already exists with this name, no error is thrown. In
    contrast to `CREATE TABLE`, which supports any variable-free
    expression, including non-constant expressions like random(), the
    default value here must be a constant.

- `DROP COLUMN [ IF EXISTS ]`

  - : This form drops a column from a table. Columns with indexes and
    table constraints can\'t be dropped.

- `ADD table_constraint [ NOT VALID ]`

  - : This form adds a new constraint to a table using the same syntax as
    [CREATE TABLE](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/create-table.md).

Some forms of ALTER TABLE that act on a single table can be combined
into a list of multiple alterations to be applied together. It is
possible to add several columns and/or drop several columns in a single
command. It is also possible to create multiple column constraints in
a single command. It is not possible to combine altering columns with
adding constraints.

## Parameters

- `IF EXISTS`

  - : Do not throw an error if the table does not exist.

- `<name>`

  - : The name (optionally schema-qualified) of an existing table to
    alter.

- `<column_name>`

  - : Name of a new or existing column.

- `<new_column_name>`

  - : New name for an existing column.

- `<new_name>`

  - : New name for the table.

- `<data_type>`

  - : Data type of the new column.

## Notes

The key word `COLUMN` is noise and can be omitted.

Changing any part of a system catalog table is not permitted.

## Examples

To add a column of type `text` to a table:

```sql
    ALTER TABLE distributors ADD COLUMN address text;
```

To drop a column from a table:

```sql
    ALTER TABLE distributors DROP COLUMN address;
```

To rename an existing column:

```sql
    ALTER TABLE distributors RENAME COLUMN address TO city;
```

To rename an existing table:

```sql
    ALTER TABLE distributors RENAME TO suppliers;
```

To add an unnamed assumed foreign key constraint to a table:

```sql
    ALTER TABLE distributors ADD ASSUMED FOREIGN KEY (address) REFERENCES addresses (address);
```

See [CREATE TABLE](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/create-table.md) for more examples of table constraints.
