CREATE KEYSPACE

AttentionThis page documents an earlier version. Go to the latest (v2.1)version.

Synopsis

The CREATE KEYSPACE statement creates a keyspace that functions as a grouping mechanism for database objects (such as tables or types).

Syntax

Diagram

create_keyspace

CREATE KEYSPACE - 图1

keyspace_properties

CREATE KEYSPACE - 图2

Grammar

  1. create_keyspace ::= CREATE { KEYSPACE | SCHEMA } [ IF NOT EXISTS ] keyspace_name
  2. [ WITH REPLICATION '=' '{' keyspace_property '}']
  3. [ AND DURABLE_WRITES '=' { true | false } ]
  4. keyspace_property ::= property_name = property_value

Where

  • keyspace_name and property_name are identifiers.
  • property_value is a literal of either boolean, text, or map datatype.

Semantics

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

Examples

  1. cqlsh> CREATE KEYSPACE example;
  1. cqlsh> DESCRIBE KEYSPACES;
  1. example system_schema system_auth system
  1. cqlsh> DESCRIBE example;
  1. CREATE KEYSPACE example WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': '3'} AND DURABLE_WRITES = true;
  1. cqlsh> CREATE SCHEMA example;
  1. SQL error: Keyspace Already Exists
  2. CREATE SCHEMA example;
  3. ^^^^^^

See Also

DROP KEYSPACEUSEOther CQL Statements