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

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.firebolt.io/feedback

```json
{
  "path": "/reference-sql/commands/data-definition/create-fact-dimension-table-as-select",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

> Reference and syntax for the CTAS SQL command.

# CREATE TABLE AS SELECT (CTAS)

Creates a table and loads data into it based on the [SELECT](/reference-sql/commands/queries/select) query. The table column names and types are automatically inferred based on the output columns of the [SELECT](/reference-sql/commands/queries/select). When specifying explicit column names, those override the column names inferred from `SELECT`.

## Syntax

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
CREATE [FACT|DIMENSION] TABLE [IF NOT EXISTS] <table_name>
[(<column_name>[, ...n] )]
[PRIMARY INDEX <column_name>[, <column_name>[, ...n]]]
[PARTITION BY <column_name>[, <column_name>[, ...n]]]
AS <select_query>
```

## Parameters

| Parameter        | Description                                                                                                  |
| :--------------- | :----------------------------------------------------------------------------------------------------------- |
| `<table_name>`   | An identifier that specifies the name of the external table. This name should be unique within the database. |
| `<column_name>`  | An identifier that specifies the name of the column. This name should be unique within the table.            |
| `<select_query`> | Any valid select query.                                                                                      |

## Remarks

Unlike a traditional `CREATE` statement, the primary index and partition definition must come *before* the `AS` clause.
