Previous Next JavaScript must be enabled to correctly display this content

## Manage Namespaces

SHOW NAMESPACES

The SHOW NAMESPACES statement provides the list of namespaces in the system. You can specify AS JSON if you want the output to be in JSON format.

Example 1: The following statement lists the namespaces present in the system.

    SHOW NAMESPACES

Output:

    namespaces
      sysdefault

Example 2: The following statement lists the namespaces present in the system in JSON format.

    SHOW AS JSON NAMESPACES

Output:

    {"namespaces" : ["sysdefault"]}

DROP NAMESPACE

You can remove a namespace by using the DROP NAMESPACE statement.

IF EXISTS is an optional clause. If you specify this clause, and if a namespace with the same name does not exist, no error is generated. If you don't specify this clause, and if a namespace with the same name does not exist, an error is generated indicating that the namespace does not exist.

CASCADE is an optional clause that enables you to specify whether to drop the tables and their indexes in this namespace. If you specify this clause, and if the namespace contains any tables, then the namespace together with all the tables in this namespace will be deleted. If you don't specify this clause, and if the namespace contains any tables, then an error is generated indicating that the namespace is not empty.

The following statement removes the namespace named ns1.

    DROP NAMESPACE IF EXISTS ns1 CASCADE

Using APIs to drop namespaces:

You can drop a namespace using `SystemRequest` class. The `SystemRequest` class is used to perform any table-independent administrative operation. These operations are asynchronous and completion needs to be checked.

Download the full code Namespaces.java from the examples here.

    private static void dropNS(NoSQLHandle handle) throws Exception {
        String dropNSDDL = "DROP NAMESPACE " + nsName;
        SystemRequest sysreq = new SystemRequest();
        sysreq.setStatement(dropNSDDL.toCharArray());
        SystemResult sysres = handle.systemRequest​(sysreq);
        sysres.waitForCompletion​(handle, 60000,1000);
        System.out.println("Namespace " + nsName + " is dropped");
    }

You can drop a namespace using `SystemRequest` class. The `SystemRequest` class is used to perform any table-independent administrative operation.

Download the full code Namespaces.py from the examples here.

    def drop_ns(handle):
       statement = '''DROP NAMESPACE ns1'''
       sysreq = SystemRequest().set_statement(statement)
       sys_result = handle.system_request(sysreq)
       sys_result.wait_for_completion(handle, 40000, 3000)
       print('Namespace: ns1 is dropped')

You can drop a namespace using `SystemRequest` class. The `SystemRequest` class is used to perform any table-independent administrative operations. These are potentially long-running operations and completion of the operation needs to be checked.

Download the full code Namespaces.go from the examples here.

    func dropNS(client *nosqldb.Client, err error)(){
        stmt := fmt.Sprintf("DROP NAMESPACE ns1")
        sysReq := &nosqldb.SystemRequest{
    		Statement: stmt,
        }
        sysRes, err := client.DoSystemRequest(sysReq)
        _, err = sysRes.WaitForCompletion(client, 60*time.Second, time.Second)
        if err != nil {
            fmt.Printf("Error finishing CREATE NAMESPACE request: %v\n", err)
            return
        }
        fmt.Println("Dropped Namespace ns1 ")
        return
    }

You can create namespace using `adminDDL` method. The `adminDDL` method is used to perform any table-independent administrative operation.

Download the full JavaScript code Namespaces.js from here and the full TypeScript code Namespaces.ts from here.

    async function dropNS(handle) {
       const dropNS = `DROP NAMESPACE ns1`;
       let res = await handle.adminDDL(dropNS);
       console.log('Namespace dropped: ns1' );
    }

The `ExecuteAdminSync` method is used to perform any table-independent administrative operations.

Download the full code Namespaces.cs from the examples here.

    private static async Task dropNS(NoSQLClient client){
       var sql = $@"DROP NAMESPACE ns1";
       var adminResult = await client.ExecuteAdminAsync(sql);
       // Wait for the operation completion
       await adminResult.WaitForCompletionAsync();
       Console.WriteLine("Dropped namespace ns1");
    }