Source: https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/ddl/graph/create/ Documentation version: v5.3.2 # CREATE GRAPH statement The CREATE GRAPH statement creates a persistent graph (also known as a graph) in the schema of the current session or a specified schema. The newly created graph is owned by the user executing this statement. The owner of the graph can [rename](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/ddl/graph/rename/) or [drop](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/ddl/graph/drop/) the graph after it is created. The ownership of the graph can be transferred to another user by using [ALTER OWNER](https://dev-docs.nebula-graph.io/v5.3.2/server-admin/authorization/alter-owner/). Apart from graphs, you can also [create temporary graphs](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/ddl/graph-projection/create/). For a thorough comparison between graphs and temporary graphs, see [Graph vs Temporary Graph](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/overview/versus/). Note An operation involving a non-default schema or an object in it requires access to the schema, either implicitly or through an explicit `USAGE` grant, as well as the privilege required for the operation. The schema access check and the privilege check for the requested operation are independent; satisfying one does not satisfy the other. Schema access control does not apply to temporary graphs or built-in procedures and functions. For more information, see [Schema access control](https://dev-docs.nebula-graph.io/v5.3.2/server-admin/authorization/schema-access-control/). ## Prerequisites - A graph type is created. For more information, see [CREATE GRAPH TYPE](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/ddl/graph-type/create/). - To create a graph, you must be granted to perform the action `CREATE GRAPH` on the corresponding schema. For more information, see [Roles and privileges](https://dev-docs.nebula-graph.io/v5.3.2/server-admin/authorization/). ## Syntax diagramsource create_graph_statement ```` create_graph_statement ::= 'CREATE' 'PROPERTY'? 'GRAPH' ('IF NOT EXISTS')? (schema_reference '/')? graph_name ('::' | 'TYPED' )? (schema_reference '/')? graph_type_name ```` ## Parameters ### `IF NOT EXISTS` This clause checks if a graph with the same name already exists. If it does already exist, the graph is not created and no exception is thrown. If you do not specify this clause, an exception is thrown if a graph with the same name already exists. ### `schema_reference` The reference to the path of the schema. This parameter can be used to specify the schema path of the graph to be created and the schema path of the graph type based on which the graph is created respectively. These two schema paths must be consistent. These two schema paths must be consistent. Both absolute and relative schema paths can be used in the statement. When the schema path is provided, the graph is created in the specified schema; otherwise, it is created in the schema of the current session. The specified graph type must exist prior to creation of graph. For information about setting and viewing the schema, see [SESSION SET](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/sessions/set/) and [SHOW CURRENT_SCHEMA](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/data-admin/show/show-current-schema/). ### `graph_name` The name of the graph to be created. `graph_name` must be an identifier. For more information about identifiers, see [Rules for naming identifiers](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/overview/keywords-identifiers/#rules_for_naming_identifiers). ### `graph_type_name` The name of the graph type based on which the graph is created. For more information, see [CREATE GRAPH TYPE](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/ddl/graph-type/create/). The graph elements (nodes and edges) in the new graph are created based on the graph element types (node types and edge types) defined in the referenced graph type. Even if the graph elements in different graphs have the same identifiers, they are NOT regarded as the same entity. ## Examples ### Create a graph in the current schema ```` CREATE GRAPH IF NOT EXISTS movie TYPED movie_type ```` The preceding example demonstrates how the graph `movie` introduced in [Example dataset](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/overview/example-dataset/) is created based on the graph type `movie_type`. ### Create a graph in a specified schema ```` ''' // Create a schema CREATE SCHEMA IF NOT EXISTS /my_schema ''' ''' // Set the schema for the current session SESSION SET SCHEMA /my_schema ''' ''' // Create a graph type in the specified schema CREATE GRAPH TYPE IF NOT EXISTS /default_schema/my_graph_type AS { NODE Person (LABEL Person {id INT64 PRIMARY KEY, name STRING}) } ''' ''' // Create a graph CREATE GRAPH IF NOT EXISTS /default_schema/my_graph TYPED /default_schema/my_graph_type ''' ```` The preceding example demonstrates how the graph `my_graph` is created based on the graph type `my_graph_type` in the `/default_schema` when the schema in the current session is set to `/my_schema`. ## More information - [DESCRIBE GRAPH](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/data-admin/describe/describe-graph/) - [SHOW GRAPHS](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/data-admin/show/show-graphs/) - [SHOW CREATE GRAPH](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/data-admin/show/show-create-graph/)