How to create a graph table in SQL Serevr 2017

26 September,2018 by Jack Vamvas

Question: How do I create a graph table in SQL Server 2017?

 

Answer: To create a graph database table  uses similar syntax as the CREATE TABLE syntax with the addition of  the AS NODE  keyword  or the AS EDGE at the end of the CREATE TABLE syntax.

 

Normally you would create a table such as :

CREATE TABLE dbo.MyNode (ID int , NAME varchar(30));

In the graph table CREATE  you would do it like:

CREATE TABLE dbo.MyNode (ID int , NAME varchar(30)) AS NODE;

or

CREATE TABLE dbo.MyEdge(ID int , NAME varchar(30)) AS EDGE ;

 

Once you've created the tables you can observer your tables in SSMS via the Object Explorer in a folder called Graph tables , under the specific database.

When you expand on the columns , you'll notice some auto generated fields. They can be accessed either via the short name or with the full name - which includes the GUID.

 

 If you attempt to run the syntax above on SQL Server versions lower than SQL Server 2017 , you'll get this message:

 Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'AS'.

 

 Graph tables are supported from SQL Server 2017 and above . To check your SQL Server version read How to use parsename with SERVERPROPERTY('productversion')

 


Author: Jack Vamvas (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How to create a graph table in SQL Serevr 2017


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer