CREATE TABLE ... AS creates a new table from a .
The
CREATE TABLE AS statement performs a schema change. For more information about how online schema changes work in CockroachDB, see .Intended use
Tables created withCREATE TABLE ... AS are intended to persist the
result of a query for later reuse.
This can be more efficient than a when the
following two conditions are met:
- The result of the query is used as-is multiple times.
- The copy needs not be kept up-to-date with the original table over time.
Required privileges
The user must have theCREATE on the parent database.
Synopsis
- Basic
- Expanded
Parameters
Limitations
The default rules for apply. The of tables created withCREATE TABLE ... AS is not automatically derived from the query results. You must specify new primary keys at table creation. For examples, see .
Examples
Setup
The following examples use MovR, a fictional vehicle-sharing application, to demonstrate CockroachDB SQL statements. For more information about the MovR example application and dataset, see . To follow along, run to start a temporary, in-memory cluster with themovr dataset preloaded:

