Previous Next JavaScript must be enabled to correctly display this content

## Creating a namespace

A namespace defines a group of tables, within which all of the table names must be uniquely identified. Namespaces permit you to do table privilege management as a group operation. You can grant authorization permissions to a namespace to determine who can access both the namespace and the tables within it. Namespaces permit tables with the same name to exist in your database store. To access such tables, you can use a fully qualified table name. A fully qualified table name is a table name preceded by its namespaces, followed with a colon (:), such as `ns1:table1`.

All tables are part of some namespace. There is a default Oracle NoSQL Database namespace, called `sysdefault`. All tables are assigned to the default `sysdefault` namespace, until or unless you create other namespaces, and create new tables within them. You can't change an existing table's namespace. Tables in `sysdefault` namespace do not require a fully qualified name and can work with just the table name.

You can add a new namespace by using the `CREATE NAMESPACE` statement.

    CREATE NAMESPACE [IF NOT EXISTS] namespace_name

Note:

Namespace names starting with `sys` are reserved. You cannot use the prefix `sys` for any namespaces.
The following statement defines a namespace named `ns1`.

    CREATE NAMESPACE IF NOT EXISTS ns1

Using APIs to create namespaces:

You can create 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 createNS(NoSQLHandle handle) throws Exception {
       String createNSDDL = "CREATE NAMESPACE IF NOT EXISTS ns1";
       SystemRequest sysreq = new SystemRequest();
       sysreq.setStatement(createNSDDL.toCharArray());
       SystemResult sysres = handle.systemRequest​(sysreq);
       sysres.waitForCompletion​(handle, 60000,1000);
       System.out.println("Namespace " + nsName + " is created");
    }

You can create 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 create_ns(handle):
       statement = '''CREATE NAMESPACE IF NOT EXISTS ns1'''
       sysreq = SystemRequest().set_statement(statement)
       sys_result = handle.system_request(sysreq)
       sys_result.wait_for_completion(handle, 40000, 3000)
       print('Created namespace: ns1')

You can create 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 createNS(client *nosqldb.Client, err error)(){
        stmt := fmt.Sprintf("CREATE NAMESPACE IF NOT EXISTS 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("Created 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 createNS(handle) {
       const createNS = `CREATE NAMESPACE IF NOT EXISTS ns1`;
       let res = await handle.adminDDL(createNS);
       console.log('Namespace created: 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 createNS(NoSQLClient client){
       var sql =
            $@"CREATE NAMESPACE IF NOT EXISTS ns1";
       var adminResult = await client.ExecuteAdminAsync(sql);
       // Wait for the operation completion
       await adminResult.WaitForCompletionAsync();
       Console.WriteLine("  Created namespace ns1");
    }