---
title: "CREATE KEYSPACE"
url: "https://docs.yugabyte.com/stable/api/ycql/ddl_create_keyspace/"
---

# CREATE KEYSPACE

Use the CREATE KEYSPACE statement to create a keyspace that functions as a grouping mechanism for database objects, such as tables or types.

## Synopsis

Use the `CREATE KEYSPACE` statement to create a `keyspace` that functions as a grouping mechanism for database objects, (such as [tables](/stable/api/ycql/ddl_create_table "tables") or [types](/stable/api/ycql/ddl_create_type "types")).

## Syntax

### Diagram

#### create\_keyspace

CREATEKEYSPACESCHEMAIFNOTEXISTS[keyspace\_name](/stable/api/ycql/grammar_diagrams#keyspace-name)[keyspace\_properties](#keyspace-properties)

#### keyspace\_properties

WITHREPLICATION={,[keyspace\_property](/stable/api/ycql/grammar_diagrams#keyspace-property)}ANDDURABLE\_WRITES=truefalse

### Grammar

```ebnf
create_keyspace ::= CREATE { KEYSPACE | SCHEMA } [ IF NOT EXISTS ] keyspace_name
                       [ WITH REPLICATION '=' '{' keyspace_property '}']
                       [ AND DURABLE_WRITES '=' { true | false } ]

keyspace_property ::= property_name = property_value
```

Where

- `keyspace_name` and `property_name` are identifiers.
- `property_value` is a literal of either [boolean](/stable/api/ycql/type_bool "boolean"), [text](/stable/api/ycql/type_text "text"), or [map](/stable/api/ycql/type_collection "map") data type.

## Semantics

- An error is raised if the specified `keyspace_name` already exists unless `IF NOT EXISTS` option is present.
- Cassandra's CQL keyspace properties are supported in the syntax but have no effect internally (where YugabyteDB defaults are used instead).

## Examples

```sql
ycqlsh> CREATE KEYSPACE example;
```

```sql
ycqlsh> DESCRIBE KEYSPACES;
```

```output
example  system_schema  system_auth  system
```

```sql
ycqlsh> DESCRIBE example;
```

```sql
CREATE KEYSPACE example WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': '3'} AND DURABLE_WRITES = true;
```

```sql
ycqlsh> CREATE SCHEMA example;
```

```output
SQL error: Keyspace Already Exists
CREATE SCHEMA example;
^^^^^^
```

## See also

- [ALTER KEYSPACE](/stable/api/ycql/ddl_alter_keyspace "ALTER KEYSPACE")
- [DROP KEYSPACE](/stable/api/ycql/ddl_drop_keyspace "DROP KEYSPACE")
- [USE](/stable/api/ycql/ddl_use "USE")
