CREATE KEYSPACE
This page documents the preview version (v2.23). Preview includes features under active development and is for development and testing only. For production, use the stable version (v2024.1). To learn more, see Versioning.
Synopsis
Use the CREATE KEYSPACE statement to create a keyspace that functions as a grouping mechanism for database objects, (such as tables or types).
Syntax
Diagram
create_keyspace
keyspace_properties
Grammar
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_nameandproperty_nameare identifiers.property_valueis a literal of either boolean, text, or map data type.
Semantics
- An error is raised if the specified
keyspace_namealready exists unlessIF NOT EXISTSoption is present. - Cassandra's CQL keyspace properties are supported in the syntax but have no effect internally (where YugabyteDB defaults are used instead).
Examples
ycqlsh> CREATE KEYSPACE example;
ycqlsh> DESCRIBE KEYSPACES;
example system_schema system_auth system
ycqlsh> DESCRIBE example;
CREATE KEYSPACE example WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': '3'} AND DURABLE_WRITES = true;
ycqlsh> CREATE SCHEMA example;
SQL error: Keyspace Already Exists
CREATE SCHEMA example;
^^^^^^