microsoft / microsoft/DacFx

Not Null Persisted Computed Column Permanent Schema Diff

Open
#500 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
460
Forks
29
Avg merge
4d 9h
Merged PRs (30d)
7

Description

  • 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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue from the provided sqlproj table definition and inspect the generated deployment script for the persisted computed column. The fix is complete when a NOT NULL persisted computed column no longer produces an unnecessary DROP COLUMN and ADD COLUMN operation, while the contrasting examples continue to behave correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.