---
title: CREATE COLLECTION AS Statements
description: This topic describes how you use the <code>CREATE COLLECTION
  AS</code> statement to both create a standalone collection and populate it
  with the results of a query.
pubDate: 2026-08-17T09:53:44.266Z
antora:
  editUrl: https://github.com/couchbaselabs/docs-columnar/edit/main/modules/sqlpp/pages/5_dml_create_as.adoc
  xref: xref:analytics:sqlpp:5_dml_create_as.adoc[]
---

[Consult the llms.txt file for a full list of contents](/llms.txt)
[View original HTML](/analytics/sqlpp/5_dml_create_as.html)

# CREATE COLLECTION AS Statements

> This topic describes how you use the `CREATE COLLECTION AS` statement to both create a standalone collection and populate it with the results of a query. 

## [](#cca)Syntax

**CreateCollectionAs EBNF** 

```EBNF
CreateCollectionAs ::= "CREATE" "ANALYTICS"? "COLLECTION" ("IF" "NOT" "EXISTS")?
                        QualifiedName
                        "PRIMARY" "KEY" "(" FieldList ")" ( "AUTOGENERATED" )?
                        "AS"
                        "SelectClause"
```

**CreateCollectionAs Diagram** 

!["CREATE" "COLLECTION" ("IF" "NOT" "EXISTS")? QualifiedName "PRIMARY" "KEY" "(" FieldList ")" ( "AUTOGENERATED" )? "AS" "SelectClause"](_images/CreateCollectionAs.png) 

**Show SelectClause Diagram** 

![SELECT](_images/SelectClause.png) 

SelectClause

**Show Projection Diagram** 

![(Expr ("AS"? Identifier)?) | (VariableRef ".")? "*"](_images/Projection.png) 

Projection

For more information about SELECT clause syntax, see [Queries](3%5Fquery.md#Select%5Fclauses).

## [](#example)Example

In this example, you create a standalone collection, `travel-sample.inventory.restaurants` and specify that you want the system to autogenerate its primary key. You then select a subset of the documents—those with an activity of eat—in the existing `travel-sample.inventory.landmark` [sample data collection](../intro/examples.md#travel-sample) to populate the new collection.

```SQL++
  CREATE COLLECTION `travel-sample`.inventory.restaurants
    PRIMARY KEY (restId: UUID) AUTOGENERATED
    AS
    SELECT *
    FROM `travel-sample`.inventory.landmark
    WHERE activity = "eat";
```

After you use `CREATE COLLECTION AS`, you can run `ANALYZE COLLECTION` on the collection to update the data sample used by cost-based optimization (CBO). See [Cost-Based Optimizer for Capella Analytics Services](5b%5Fcbo.md).

## [](#see-also)See Also

* [CREATE a Standalone Collection](5%5Fddl%5Fstandalone.md)
* [Access and Organize Data in Capella Analytics Services](../sources/database-objects.md)
* [Cost-Based Optimizer for Capella Analytics Services](5b%5Fcbo.md)