Need to create a view from a SQL Server Graph Table that does not include the hidden graph_id column

127 Views Asked by At

The table was created as a NODE, therefore SQL Server adds a graph_id_xxxxxx column between others. I create a view with the following sentence:

CREATE VIEW FILE_VIEW1 AS
SELECT
      [NAME]
FROM [dbo].[FILE_NAME]

But when I see the columns in the view, the graph_id_xxxx column is still there even when it was not part of the select statement in the view.

Would appreciate any help.

1

There are 1 best solutions below

1
David Browne - Microsoft On

While those columns appear in sys.columns (not sure why) for the view, they aren't accessable and don't appear when you select * from the view.

CREATE TABLE Person (ID INTEGER PRIMARY KEY, Name VARCHAR(100), Age INT) AS NODE;
CREATE TABLE friends (StartDate date) AS EDGE;
go
create view vPerson as select Name from Person
go
select * from Person 
select * from vPerson

You can eliminate them from the view metadata by pushing the graph table query into a subquery expression in the view, eg

create or alter view [dbo].[vPerson] as 
with q as (select Name from Person)
select * from q