USE
Synopsis
The USE
keyspace statement specifies a default keyspace for the current client session. When a database object (such as table or type) name does not identify a keyspace, this default keyspace is used.
Syntax
Diagram
Grammar
use_keyspace ::= USE keyspace_name;
Where
keyspace_name
must be an identifier that cannot be any reserved keyword and cannot contains whitespaces, or it has to be double-quoted.
Semantics
- If the specified keyspace does not exist, an error is raised.
- Any unqualified table or type name will use the current default keyspace (or raise an error if no keyspace is set).
Examples
Create and use keyspaces
cqlsh> CREATE KEYSPACE example;
cqlsh> CREATE KEYSPACE other_keyspace;
cqlsh> USE example;
Create a table in the current keyspace
cqlsh:example> CREATE TABLE test(id INT PRIMARY KEY);
cqlsh:example> INSERT INTO test(id) VALUES (1);
cqlsh:example> SELECT * FROM test;
id
id
1
Create a table in another keyspace
cqlsh:example> CREATE TABLE other_keyspace.test(id INT PRIMARY KEY);
cqlsh:example> INSERT INTO other_keyspace.test(id) VALUES (2);
cqlsh:example> SELECT * FROM other_keyspace.test;
id
id
2
See also
当前内容版权归 YugabyteDB 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 YugabyteDB .