Join us on
Star us on
Get Started
Slack
GitHub
Get Started
v2.0 (latest version) v1.3 (earlier version) v1.2 (earlier version) v1.1 (earlier version) v1.0 (earlier version)
  • GET STARTED
    • Quick Start
      • 1. Install YugabyteDB
      • 2. Create Local Cluster
      • 3. Explore YSQL
      • 4. Build an app
        • Java
        • NodeJS
        • Go
        • Python
        • Ruby
        • C#
        • PHP
        • C++
        • C
    • Introduction
    • Explore Core
      • 1. Linear Scalability
      • 2. Fault Tolerance
      • 3. Global Distribution
      • 4. Auto Sharding
      • 5. Tunable Reads
      • 6. Observability
  • USER GUIDES
    • Develop
      • Learn App Dev
        • 1. SQL vs NoSQL
        • 2. Data Modeling
        • 3. Data Types
        • 4. ACID Transactions
        • 5. Aggregations
        • 6. Batch Operations
      • Ecosystem Integrations
        • Apache Kafka
        • Apache Spark
        • JanusGraph
        • KairosDB
        • Presto
        • Metabase
      • Real World Examples
        • E-Commerce App
        • IoT Fleet Management
        • Retail Analytics
      • Explore Sample Apps
    • Deploy
      • Checklist
      • Manual Deployment
        • 1. System Configuration
        • 2. Install Software
        • 3. Start YB-Masters
        • 4. Start YB-TServers
        • 5. Verify Deployment
      • Kubernetes
        • Helm Chart
        • Helm Configuration
        • Local SSD
      • Docker
      • Public Clouds
        • Amazon Web Services
        • Google Cloud Platform
        • Microsoft Azure
      • Pivotal Cloud Foundry
      • Enterprise Edition
        • 1. Prepare Cloud Env
        • 2. Install Admin Console
        • 3. Configure Admin Console
        • 4. Configure Cloud Providers
    • Benchmark
      • Performance
      • YCSB
      • Large Datasets
    • Secure
      • Security Checklist
      • Authentication
      • Authorization
        • 1. RBAC Model
        • 2. Create Roles
        • 3. Grant Permissions
      • TLS Encryption
        • 1. Prepare Nodes
        • 2. Server-Server Encryption
        • 3. Client-Server Encryption
        • 4. Connect to Cluster
    • Manage
      • Backup and Restore
        • Backing Up Data
        • Restoring Data
      • Data Migration
        • Bulk Import
        • Bulk Export
      • Change Cluster Config
      • Upgrade Deployment
      • Diagnostics Reporting
      • Enterprise Edition
        • Create Universe - Multi-Zone
        • Create Universe - Multi-Region
        • Edit Universe
        • Edit Config Flags
        • Health Checking and Alerts
        • Create/Edit Instance Tags
        • Node Status & Actions
        • Read Replicas
        • Backup & Restore
        • Upgrade Universe
        • Delete Universe
    • Troubleshoot
      • Troubleshooting Overview
      • Cluster Level Issues
        • YCQL Connection Issues
        • YEDIS Connection Issues
      • Node Level Issues
        • Check Processes
        • Inspect Logs
        • System Stats
      • Enterprise Edition
        • Troubleshoot Universes
  • REFERENCE
    • APIs
      • YSQL
        • Commands
          • ABORT
          • ALTER DOMAIN
          • ALTER TABLE
          • BEGIN TRANSACTION
          • COMMIT
          • COPY
          • CREATE DATABASE
          • CREATE DOMAIN
          • CREATE INDEX
          • CREATE SCHEMA
          • CREATE SEQUENCE
          • CREATE TABLE
          • CREATE TABLE AS
          • CREATE USER
          • CREATE VIEW
          • DEALLOCATE
          • DELETE
          • DROP DATABASE
          • DROP DOMAIN
          • DROP SEQUENCE
          • DROP TABLE
          • END TRANSACTION
          • EXECUTE
          • EXPLAIN
          • INSERT
          • PREPARE
          • RESET
          • ROLLBACK
          • SELECT
          • SET
          • SET TRANSACTION
          • SHOW
          • SHOW TRANSACTION
          • TRUNCATE
          • UPDATE
        • Datatypes
          • Binary
          • Boolean
          • Character
          • Date-time
          • Json
          • Money
          • Numeric
          • Serial
          • UUID
        • Expressions
          • currval()
          • lastval()
          • nextval()
        • Keywords
        • Reserved Names
      • YCQL
        • Quick Start YCQL
        • ALTER KEYSPACE
        • ALTER ROLE
        • ALTER TABLE
        • CREATE INDEX
        • CREATE KEYSPACE
        • CREATE ROLE
        • CREATE TABLE
        • CREATE TYPE
        • DROP INDEX
        • DROP KEYSPACE
        • DROP ROLE
        • DROP TABLE
        • DROP TYPE
        • GRANT PERMISSION
        • GRANT ROLE
        • REVOKE PERMISSION
        • REVOKE ROLE
        • USE
        • INSERT
        • SELECT
        • UPDATE
        • DELETE
        • TRANSACTION
        • TRUNCATE
        • Simple Value
        • Subscript
        • Function Call
        • Operator Call
        • BLOB
        • BOOLEAN
        • MAP, SET, LIST
        • FROZEN
        • INET
        • Integer & Counter
        • Non-Integer
        • TEXT
        • Date & Time Types
        • UUID & TIMEUUID
        • JSONB
        • Date & Time Functions
    • CLIs
      • yb-ctl
      • yb-docker-ctl
      • yb-master
      • yb-tserver
      • ysqlsh
      • cqlsh
    • Tools
      • TablePlus
  • RELEASES
    • Release History
      • v1.2.12
      • v1.2.11
      • v1.2.10
      • v1.2.9
      • v1.2.8
      • v1.2.6
      • v1.2.5
      • v1.2.4
  • CONCEPTS
    • Architecture
      • Design Goals
      • Layered Architecture
      • Basic Concepts
        • Universe
        • YB-TServer
        • YB-Master
        • Acknowledgements
      • Query Layer
        • Overview
      • DocDB Store
        • Sharding
        • Replication
        • Persistence
        • Performance
      • DocDB Transactions
        • Isolation Levels
        • Single Row Transactions
        • Distributed Transactions
        • Transactional IO Path
  • FAQ
    • Comparisons
      • CockroachDB
      • Google Cloud Spanner
      • MongoDB
      • FoundationDB
      • Amazon DynamoDB
      • Azure Cosmos DB
      • Apache Cassandra
      • Redis In-Memory Store
      • Apache HBase
    • Other FAQs
      • Product
      • Architecture
      • Enterprise Edition
      • API Compatibility
  • CONTRIBUTOR GUIDES
    • Get Involved
  • Misc
    • YEDIS
      • Quick Start
      • Develop
        • Client Drivers
          • C
          • C++
          • C#
          • Go
          • Java
          • NodeJS
          • Python
      • API Reference
        • APPEND
        • AUTH
        • CONFIG
        • CREATEDB
        • DELETEDB
        • LISTDB
        • SELECT
        • DEL
        • ECHO
        • EXISTS
        • EXPIRE
        • EXPIREAT
        • FLUSHALL
        • FLUSHDB
        • GET
        • GETRANGE
        • GETSET
        • HDEL
        • HEXISTS
        • HGET
        • HGETALL
        • HINCRBY
        • HKEYS
        • HLEN
        • HMGET
        • HMSET
        • HSET
        • HSTRLEN
        • HVALS
        • INCR
        • INCRBY
        • KEYS
        • MONITOR
        • PEXPIRE
        • PEXPIREAT
        • PTTL
        • ROLE
        • SADD
        • SCARD
        • RENAME
        • SET
        • SETEX
        • PSETEX
        • SETRANGE
        • SISMEMBER
        • SMEMBERS
        • SREM
        • STRLEN
        • ZRANGE
        • TSADD
        • TSCARD
        • TSGET
        • TSLASTN
        • TSRANGEBYTIME
        • TSREM
        • TSREVRANGEBYTIME
        • TTL
        • ZADD
        • ZCARD
        • ZRANGEBYSCORE
        • ZREM
        • ZREVRANGE
        • ZSCORE
        • PUBSUB
        • PUBLISH
        • SUBSCRIBE
        • UNSUBSCRIBE
        • PSUBSCRIBE
        • PUNSUBSCRIBE
> APIs > YCQL >

USE

Attention

This page documents an earlier version. Go to the latest (v2.0)version.

    • Synopsis
    • Syntax
      • Diagram
      • Grammar
    • Semantics
    • Examples
      • Create and use keyspaces
      • Create a table in the current keyspace
      • Create a table in another keyspace
    • See Also

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

USEkeyspace_name

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
----
  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
----
  2

See Also

ALTER KEYSPACE CREATE KEYSPACE DROP KEYSPACE Other CQL Statements

    • Synopsis
    • Syntax
      • Diagram
      • Grammar
    • Semantics
    • Examples
      • Create and use keyspaces
      • Create a table in the current keyspace
      • Create a table in another keyspace
    • See Also
APIs
REVOKE ROLE
APIs
INSERT
Talk to Community
  • Slack
  • Github
  • Forum
  • StackOverflow
Yugabyte
Contact Us
Copyright © 2017-2019 Yugabyte, Inc. All rights reserved.