$node_id
column is created, which uniquely identifies a given node in the database. The values in $node_id
are automatically generated and are a combination of object_id
of that node table and an internally generated bigint value. However, when the $node_id
column is selected, a computed value in the form of a JSON string is displayed. Also, $node_id
is a pseudo column, that maps to an internal name with hex string in it. When you select $node_id
from the table, the column name will appear as $node_id_<hex_string>
. Using pseudo-column names in queries is the recommended way of querying the internal $node_id
column and using internal name with hex string should be avoided.$node_id
column at the time of creation of node table, but if one is not created, a default unique, nonclustered index is automatically created. However, any index on a graph pseudo column is created on the underlying internal columns. That is, an index created on the $node_id
column, will appear on the internal graph_id_<hex_string>
column.Column name | Description |
---|---|
$edge_id | Uniquely identifies a given edge in the database. It is a generated column and the value is a combination of object_id of the edge table and a internally generated bigint value. However, when the $edge_id column is selected, a computed value in the form of a JSON string is displayed. $edge_id is a pseudo-column, that maps to an internal name with hex string in it. When you select $edge_id from the table, the column name will appear as $edge_id_<hex_string> . Using pseudo-column names in queries is the recommended way of querying the internal $edge_id column and using internal name with hex string should be avoided. |
$from_id | Stores the $node_id of the node, from where the edge originates. |
$to_id | Stores the $node_id of the node, at which the edge terminates. |
$from_id
and $to_id
columns. In the first release, it is not possible to define constraints on the edge table, to restrict it from connecting any two type of nodes. That is, an edge can connect any two nodes in the graph, regardless of their types.$node_id
column, it is recommended that users create a unique index or constraint on the $edge_id
column at the time of creation of the edge table, but if one is not created, a default unique, nonclustered index is automatically created on this column. However, any index on a graph pseudo column is created on the underlying internal columns. That is, an index created on the $edge_id
column, will appear on the internal graph_id_<hex_string>
column. It is also recommended, for OLTP scenarios, that users create an index on ($from_id
, $to_id
) columns, for faster lookups in the direction of the edge.is_node
is set to 1, that indicates that the table is a node table and if is_edge
is set to 1, that indicates that the table is an edge table.Column Name | Data Type | Description |
---|---|---|
is_node | bit | 1 = this is a node table |
is_edge | bit | 1 = this is an edge table |
sys.columns
view contains additional columns graph_type
and graph_type_desc
, that indicate the type of the column in node and edge tables.Column Name | Data Type | Description |
---|---|---|
graph_type | int | Internal column with a set of values. The values are between 1-8 for graph columns and NULL for others. |
graph_type_desc | nvarchar(60) | internal column with a set of values |
graph_type
columnColumn Value | Description |
---|---|
1 | GRAPH_ID |
2 | GRAPH_ID_COMPUTED |
3 | GRAPH_FROM_ID |
4 | GRAPH_FROM_OBJ_ID |
5 | GRAPH_FROM_ID_COMPUTED |
6 | GRAPH_TO_ID |
7 | GRAPH_TO_OBJ_ID |
8 | GRAPH_TO_ID_COMPUTED |
sys.columns
also stores information about implicit columns created in node or edge tables. Following information can be retrieved from sys.columns, however, users cannot select these columns from a node or edge table.Column Name | Data Type | is_hidden | Comment |
---|---|---|---|
graph_id_<hex_string> | BIGINT | 1 | internal graph_id column |
$node_id_<hex_string> | NVARCHAR | 0 | External node node_id column |
Column Name | Data Type | is_hidden | Comment |
---|---|---|---|
graph_id_<hex_string> | BIGINT | 1 | internal graph_id column |
$edge_id_<hex_string> | NVARCHAR | 0 | external edge_id column |
from_obj_id_<hex_string> | INT | 1 | internal from node object_id |
from_id_<hex_string> | BIGINT | 1 | Internal from node graph_id |
$from_id_<hex_string> | NVARCHAR | 0 | external from node node_id |
to_obj_id_<hex_string> | INT | 1 | internal to node object_id |
to_id_<hex_string> | BIGINT | 1 | Internal to node graph_id |
$to_id_<hex_string> | NVARCHAR | 0 | external to node node_id |
sys.node_id
the method will extract the appropriate part and return it. For example, OBJECT_ID_FROM_NODE_ID will take a $node_id
as input and will return the object_id of the table, this node belongs to.Built-in | Description |
---|---|
OBJECT_ID_FROM_NODE_ID | Extract the object_id from a node_id |
GRAPH_ID_FROM_NODE_ID | Extract the graph_id from a node_id |
NODE_ID_FROM_PARTS | Construct a node_id from an object_id and a graph_id |
OBJECT_ID_FROM_EDGE_ID | Extract object_id from edge_id |
GRAPH_ID_FROM_EDGE_ID | Extract identity from edge_id |
EDGE_ID_FROM_PARTS | Construct edge_id from object_id and identity |
Task | Related Article | Notes |
---|---|---|
CREATE TABLE | CREATE TABLE (Transact-SQL) | CREATE TABLE is now extended to support creating a table AS NODE or AS EDGE. Note that an edge table may or may not have any user-defined attributes. |
ALTER TABLE | ALTER TABLE (Transact-SQL) | Node and edge tables can be altered the same way a relational table is, using the ALTER TABLE . Users can add or modify user-defined columns, indexes or constraints. However, altering internal graph columns, like $node_id or $edge_id , will result in an error. |
CREATE INDEX | CREATE INDEX (Transact-SQL) | Users can create indexes on pseudo-columns and user-defined columns in node and edge tables. All index types are supported, including clustered and nonclustered columnstore indexes. |
CREATE EDGE CONSTRAINTS | EDGE CONSTRAINTS (Transact-SQL) | Users can now create edge constraints on edge tables to enforce specific semantics and also maintain data integrity |
DROP TABLE | DROP TABLE (Transact-SQL) | Node and edge tables can be dropped the same way a relational table is, using the DROP TABLE . However, in this release, there are no constraints to ensure that no edges point to a deleted node and cascaded deletion of edges, upon deletion of a node or node table is not supported. It is recommended that if a node table is dropped, users drop any edges connected to the nodes in that node table manually to maintain the integrity of the graph. |
Task | Related Article | Notes |
---|---|---|
INSERT | INSERT (Transact-SQL) | Inserting into a node table is no different than inserting into a relational table. The values for $node_id column is automatically generated. Trying to insert a value in $node_id or $edge_id column will result in an error. Users must provide values for $from_id and $to_id columns while inserting into an edge table. $from_id and $to_id are the $node_id values of the nodes that a given edge connects. |
DELETE | DELETE (Transact-SQL) | Data from node or edge tables can be deleted in same way as it is deleted from relational tables. However, in this release, there are no constraints to ensure that no edges point to a deleted node and cascaded deletion of edges, upon deletion of a node is not supported. It is recommended that whenever a node is deleted, all the connecting edges to that node are also deleted, to maintain the integrity of the graph. |
UPDATE | UPDATE (Transact-SQL) | Values in user-defined columns can be updated using the UPDATE statement. Updating the internal graph columns, $node_id , $edge_id , $from_id and $to_id is not allowed. |
MERGE | MERGE (Transact-SQL) | MERGE statement is supported on a node or edge table. |
Task | Related Article | Notes |
---|---|---|
SELECT | SELECT (Transact-SQL) | Nodes and edges are stored as tables internally, hence most of the operations supported on a table in SQL Server or Azure SQL Database are supported on the node and edge tables |
MATCH | MATCH (Transact-SQL) | MATCH built-in is introduced to support pattern matching and traversal through the graph. |
$from_id
and $to_id
columns of an edge using UPDATE statement. To update the nodes that an edge connects, users will have to insert the new edge pointing to new nodes and delete the previous one.query 1
, query 2
, and so on. To close an open tab, click the x
on the tab. For a closer look at query editing in MySQL Workbench, (see Section 8.1.1, “SQL Query Tab”).