Managing Namespace

To manage namespaces, run the below commands in the SQL Shell.

CREATE NAMESPACE

Example 1: Use the CREATE NAMESPACE statement to add a new namespace.

CREATE NAMESPACE IF NOT EXISTS ns1

Note:

IF NOT EXISTS clause is optional.
Output:
Statement completed successfully

SHOW NAMESPACES

Example 2: Use the show namespaces statement to show the existing namespaces.

SHOW NAMESPACES
Output:
namespaces
  ns1
  sysdefault

Example 3: To show the namespaces in a JSON format, use the statement below

SHOW AS JSON NAMESPACES
Output:
{"namespaces" : ["ns1","sysdefault"]}

DROP NAMESPACE

To delete a namespace, use the DROP NAMESPACE statement

Example 4: Delete a namespace from your store.

DROP NAMESPACE IF EXISTS ns1 CASCADE
Explanation: The above statement removes the namespace, ns1.
  • IF EXISTS is an optional clause. Specifying it prevents an error if the namespace doesn't exist. However, not including results in an error that the namespace is missing.
  • CASCADE is an optional clause. It deletes the namespace and all the tables in it collectively. If not specified, the system throws an error, stating that the namespace is not empty.

Note:

You cannot delete the default namespace, sysdefault.