Create Space Syntax¶
CREATE SPACE [IF NOT EXISTS] <space_name> [(partition_num = <part_num>, replica_factor = <raft_copy>, charset = <charset>, collate = <collate>)]
This statement creates a new space with the given name. SPACE is a region that provides physically isolated graphs in Nebula Graph. An error occurs if the database exists.
IF NOT EXISTS¶
You can use the
If NOT EXISTS keywords when creating spaces. This keyword automatically detects if the corresponding space exists. If it does not exist, a new one is created. Otherwise, no space is created.
Note: The space existence detection here only compares the space name (excluding properties).
The name uniquely identifies the space in a cluster. The rules for the naming are given in Schema Object Names
Customized Space Options¶
When creating a space, the following two customized options can be given:
partition_num specifies the number of partitions in one replica. The default value is 100.
replica_factor specifies the number of replicas in the cluster. The default replica factor is 1. The suggested number is 3 in cluster.
charset is short for character set. A character set is a set of symbols and encodings. The default value is utf8.
A collation is a set of rules for comparing characters in a character set. The default value is utf8_bin.
However, if no option is given, Nebula Graph will create the space with the default partition number, replica factor, charset and collate.
nebula> CREATE SPACE my_space_1; -- create space with default partition number and replica factor nebula> CREATE SPACE my_space_2(partition_num=10); -- create space with default replica factor nebula> CREATE SPACE my_space_3(replica_factor=1); -- create space with default partition number nebula> CREATE SPACE my_space_4(partition_num=10, replica_factor=1);