DacFx icon indicating copy to clipboard operation
DacFx copied to clipboard

Not Null Persisted Computed Column Permanent Schema Diff

Open asrichesson opened this issue 1 year ago • 1 comments

  • SqlPackage or DacFx Version: 162.4.92.3
  • .NET Framework (Windows-only) or .NET Core: both
  • Environment (local platform and source/target platforms): Microsoft SQL Server 2019 (RTM-CU27-GDR) (KB5040948) - 15.0.4382.1 (X64) Jul 1 2024 20:03:23 Copyright (C) 2019 Microsoft Corporation Express Edition (64-bit) on Windows 10 Enterprise 10.0 <X64> (Build 22631: ) (Hypervisor)

Steps to Reproduce:

  1. Create a table definition in a sqlproj
CREATE TABLE [dbo].[MyTable](    
    NormalColumn INT NOT NULL,
    ComputedColumn AS NormalColumn PERSISTED,
) ON [PRIMARY]
  1. Build and deploy this as a dacpac
  2. The computed column is dropped and recreated when it shouldn't be
ALTER TABLE [dbo].[MyTable] DROP COLUMN [ComputedColumn];

ALTER TABLE [dbo].[MyTable] ADD [ComputedColumn] AS NormalColumn PERSISTED;

Similar examples: This does not result in a column drop and create

CREATE TABLE [dbo].[MyTable](    
    NormalColumn INT NULL,
    ComputedColumn AS NormalColumn PERSISTED,
) ON [PRIMARY]

Neither does this:

CREATE TABLE [dbo].[MyTable](    
    NormalColumn INT NOT NULL,
    ComputedColumn AS NormalColumn,
) ON [PRIMARY]

And neither does this

CREATE TABLE [dbo].[MyTable](    
    NormalColumn INT NOT NULL,
    ComputedColumn AS NormalColumn PERSISTED NOT NULL,
) ON [PRIMARY]

It seems to be a combination of the NOT NULL and PERSISTED

Did this occur in prior versions? If not - which version(s) did it work in?

(DacFx/SqlPackage/SSMS/Azure Data Studio)

asrichesson avatar Sep 30 '24 21:09 asrichesson

@dzsquared since you have "persistent-schema-differences" tag maybe it should be applied to this issue too.

IVNSTN avatar Mar 26 '25 07:03 IVNSTN