azuredatastudio icon indicating copy to clipboard operation
azuredatastudio copied to clipboard

unique constraint script in script pane is not generated correctly

Open alanrenmsft opened this issue 2 years ago • 2 comments

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

alanrenmsft avatar Apr 18 '22 17:04 alanrenmsft

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.

caohai avatar May 16 '22 22:05 caohai

but if you try to do script as create in ADS image

image

please investigate how is this one generated.

alanrenmsft avatar May 16 '22 22:05 alanrenmsft