CREATE KEYSPACE
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_name
andproperty_name
are identifiers.property_value
is a literal of either boolean, text, or map data type.
Semantics
- An error is raised if the specified
keyspace_name
already exists unlessIF 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
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;
^^^^^^