# Create table statements

[Home](/rezoom-sql/master.md) > [Language](/rezoom-sql/language.md) > Create table statements

[← Common table expressions](/rezoom-sql/language/commontableexpression.md) | [Create view statements →](/rezoom-sql/language/createviewstmt.md)

## Create Table Statements

A **create table** statement is used to... create a table that will hold data.

When you create a table, you can specify:

* The columns of the table and their types
* The constraints applied to individual columns
* The constraints applied to the table as a whole

Create table statements come in two forms.

#### *create-table*

![](/files/6Q3FnIi0rvk1cVcIufns)

### Create as select

The simplest form is to just dump the output of a [*select-stmt*](/rezoom-sql/language/selectstmt.md) into a new table. This is mostly used with temporary tables, as there is no way to specify constraints on the resulting table. On the T-SQL backend, this translates to a `SELECT ... INTO tbl FROM ...`.

```sql
create temp table MyExampleTable as
    select * from AnotherTable a
    join YetAnotherTable y on a.SomeColumn = y.SomeColumn
```

### Create with column definitions

The more common form is to specify the column names, types, and constraints for the table. This is what you use to define your schema.

Each column is defined with a **column-def**.

#### *column-def*

![](/files/0FqRAwXpB1TRMzWGRAZ7)

This is often just a [*column-name*](/rezoom-sql/language/name.md) and a [*type-name*](https://github.com/rspeele/Rezoom.SQL/blob/master/doc/Language/TypeHierarchy.md), but can optionally include **column-constraints**.

#### *column-constraint*

![](/files/VT9PS3VNVcHdxIXakG8B)

A **foreign-key-clause** is a valid column constraint. This gets its own syntax diagram since it is also referenced by **table-constraint**.

#### *foreign-key-clause*

![](/files/7LaNqv9NhyhUchiCrI5t)

The supported constraints are:

* UNIQUE: This column is unique across the table.
* PRIMARY KEY: This column is the primary key of the table. If AUTOINCREMENT is specified, the column will also have a default value generated by the database when new rows are inserted.
* REFERENCES: This column is a foreign key referencing a column in another table.

### Table constraints

#### *table-constraint*

After specifying the columns of the table, you can also define some table-wide constraints that apply to more than one column. These are **table-constraints**.

![](/files/HfNmxN9UV8N4DJvJrSXg)

Some of these are just multi-column versions of the column constraints and work the same. The CHECK constraint is table-wide and should be a boolean expression, which will be checked when rows in the table are inserted or updated.

### Constraint naming

Constraints can be optionally named, but if no name is provided, one will be generated automatically according to the table name, constraint type, and related column.

Note that the default generated name for CHECK constraints will collide if you have multiple CHECK constraints on one table. In this case you should explicitly name those constraints.

***

[← Common table expressions](/rezoom-sql/language/commontableexpression.md) | [Create view statements →](/rezoom-sql/language/createviewstmt.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://humbobst.gitbook.io/rezoom-sql/language/createtablestmt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
