3.19. USE

The USE clause determines which graph a query, or query part, is executed against.

3.19.1. Introduction

The USE clause determines which graph a query, or query part, is executed against. It is supported for queries and schema commands.

3.19.2. Syntax

The USE clause can only appear as the prefix of schema commands, or as the first clause of queries:

USE <graph>
<other clauses>

Where <graph> refers to the name of a database in the DBMS.

3.19.2.1. Fabric syntax

When running queries against a Fabric database, the USE clause can also appear as the first clause of:

  • Union parts:

    USE <graph>
    <other clauses>
      UNION
    USE <graph>
    <other clauses>
  • Subqueries:

    CALL {
      USE <graph>
      <other clauses>
    }

    In subqueries, a USE clause may appear as the second clause, if directly following an importing WITH clause

When executing queries against a Fabric database, in addition to referring to databases in the DBMS, the <graph> may also refer to a graph mounted through the Fabric configuration. For more information, see Operations Manual → Fabric.

3.19.3. Examples

3.19.3.1. Query a graph by name

In this example we assume that your DBMS contains a database named myDatabase:

Query. 

USE myDatabase
MATCH (n) RETURN n

3.19.3.2. Query a Fabric graph by name

In this example we assume that we have configured a Fabric database called exampleFabricSetup. The graph that we wish to query is named exampleDatabaseName:

Query. 

USE exampleFabricSetup.exampleDatabaseName
MATCH (n) RETURN n

3.19.3.3. Query a Fabric graph by graph ID

This examples continues with a Fabric database called exampleFabricSetup.

The graph we wish to query is configured with the graph id 0, which is why we can refer to it using the built-in function graph() with the argument 0:

Query. 

USE exampleFabricSetup.graph(0)
MATCH (n) RETURN n