azuredatastudio
azuredatastudio copied to clipboard
unique constraint script in script pane is not generated correctly
Run the following script to create a node table.
CREATE TABLE [dbo].[person] (
[creationDate] DATETIME NOT NULL,
[personId] BIGINT NOT NULL,
[firstName] nvarchar (MAX) NOT NULL,
[lastName] nvarchar (MAX) NOT NULL,
[gender] nvarchar (MAX) NOT NULL,
[birthday] DATETIME NOT NULL,
[locationIP] nvarchar (50) NOT NULL,
[browserUsed] nvarchar (MAX) NOT NULL,
[LocationCityId] BIGINT NOT NULL,
CONSTRAINT PK_person PRIMARY KEY NONCLUSTERED ([personId] ASC),
CONSTRAINT Graph_Unique_Key_Person UNIQUE CLUSTERED ($node_id) WITH (DATA_COMPRESSION = PAGE)
) AS NODE;
GO
Open the newly created table in table designer and observe the script for Graph_Unique_Key_Person
constraint
CREATE TABLE [dbo].[person] (
[creationDate] DATETIME NOT NULL,
[personId] BIGINT NOT NULL,
[firstName] NVARCHAR (MAX) NOT NULL,
[lastName] NVARCHAR (MAX) NOT NULL,
[gender] NVARCHAR (MAX) NOT NULL,
[birthday] DATETIME NOT NULL,
[locationIP] NVARCHAR (50) NOT NULL,
[browserUsed] NVARCHAR (MAX) NOT NULL,
[LocationCityId] BIGINT NOT NULL,
CONSTRAINT [PK_person] PRIMARY KEY NONCLUSTERED ([personId] ASC),
CONSTRAINT [Graph_Unique_Key_Person] UNIQUE CLUSTERED ([graph_id_A1D63FA12BCD4846A147BB87EB2FADD0] ASC) WITH (DATA_COMPRESSION = PAGE)
) AS NODE;
the column is showing graph_id_A1D63FA12BCD4846A147BB87EB2FADD0
instead of $node_id
According to official doc, this seems to be the expected behavior for constraint/index created on pseudo-columns like $node_id
.
$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>.
an index created on the $node_id column, will appear on the internal graph_id_<hex_string> column.
https://docs.microsoft.com/en-us/sql/relational-databases/graphs/sql-graph-architecture?view=sql-server-ver15#:~:text=node_id%20column%2C%20will%20appear%20on%20the%20internal-,graph_id_,-%3Chex_string%3E%20column.
I also tested this script in SSDT and the behavior is the same.
but if you try to do script as create in ADS
please investigate how is this one generated.