Skip to content

Modifying persisted computed column in sql server should recreate indexes that reference it. #3595

@ctrl-shift

Description

@ctrl-shift

When a persisted computed column is defined in sql server, example:

  column "Deleted" {
    type = bit
    as {
      expr = "convert(bit, case when DeletedDate is not null then 1 else 0 end)"
      type = PERSISTED
    }
  }

has its expr modified, then the generated sql

ALTER TABLE <Name> DROP COLUMN [Deleted];
ALTER TABLE <Name> ADD [Deleted] AS (CONVERT([bit],case when [DeletedDate] IS NOT NULL then (1) else (0) end)) PERSISTED NOT NULL;
-

will fail if there are any indexes referencing this column.
Changing computed persisted column referenced by indexes should probably drop and recreate indexes referencing it if there are any.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions