I have a SSDT project and we publish databases via dacpac/sqlpackage. Now I have a existing table with duplicate records. And I am adding a UNIQUE constraint so that the records should not be duplicated. This is how my table script looks like.
CREATE TABLE [AM].[WorkflowStep]
(
[Id] INT NOT NULL PRIMARY KEY IDENTITY,
[StepName] NVARCHAR(200) NOT NULL,
[IsAutomated] BIT NOT NULL DEFAULT 0,
[TenantId] UNIQUEIDENTIFIER NOT NULL,
*CONSTRAINT [UNIQUE_STEP] UNIQUE (StepName, IsAutomated, TenantId)*
)
The constraint is newly added. I was expecting the sqlpackage.exe to generate publish script with constraint added with NOCHECK Option and then finally altered with CHECK option. But that is not happening. The script has only an alter table option.
ALTER TABLE [WorkflowStep]
ADD CONSTRAINT [UNIQUE_STEP] UNIQUE NONCLUSTERED ([StepName] ASC, [IsAutomated] ASC, [TenantId] ASC);
Can someone throw light on why it is so? Is this specific to UNIQUE constraints. I have other constraints in other tables for which the sqlpackage adds constraints with NOCHECK option initially but they are foreign key references.`