Skip to content

Create TAG / EDGE Syntax

CREATE {TAG | EDGE} [IF NOT EXISTS] {<tag_name> | <edge_name>}
    ([<create_definition>, ...])

<create_definition> ::=
    <prop_name> <data_type>

<tag_edge_options> ::=
    <option> [, <option> ...]

<option> ::=
    TTL_DURATION [=] <ttl_duration>
    | TTL_COL [=] <prop_name>
    | DEFAULT <default_value>

Nebula Graph's schema is composed of tags and edges, either of which may have properties. CREATE TAG statement defines a tag with the given name. While CREATE EDGE statement is to define an edge type.

The features of this syntax are described in the following sections:


You can use the If NOT EXISTS keywords when creating tags or edges. This keyword automatically detects if the corresponding tag or edge exists. If it does not exist, a new one is created. Otherwise, no tag or edge is created.

Note: The tag or edge existence detection here only compares the tag or edge name (excluding properties).

Tag Name and Edge Type Name

  • tag_name and edge_name

    The name of tags and edgeTypes must be unique within the space. Once the name is defined, it can not be altered. The rules of tag and edgeType names are the same as those for names of spaces. See Schema Object Name for detail.

Property Name and Data Type

  • prop_name

    prop_name indicates the name of properties. It must be unique for each tag or edgeType.

  • data_type

    data_type represents the data type of each property. For more information about data types that Nebula Graph supports, see data-type section.

    NULL and NOT NULL constrain are not supported yet when creating tags/edges (comparing with relational databases).

  • Default Constraint

    You can set the default value of a property when creating a tag/edge with the DEFAULT constraint. The default value will be added to all new vertices and edges IF no other value is specified. Also you can write a user-specified value if you don't want to use the default one.

    Using Alter to change the default value is not supported.


nebula> CREATE TAG course(name string, credits int)
nebula> CREATE TAG notag()  -- empty properties

nebula> CREATE EDGE follow(start_time timestamp, grade double)
nebula> CREATE EDGE noedge()  -- empty properties

nebula> CREATE TAG player_with_default(name string, age int DEFAULT 20)  -- age is set to 20 by default
nebula> CREATE EDGE follow_with_default(start_time timestamp DEFAULT 0, grade double DEFAULT 0.0)  -- start_time is set to 0 by default, grade is set to 0.0 by default