Troubleshooting Guide: Error 4919 – PERSISTED Attribute Cannot Be Altered
Why This Error Happens
Error 4919 occurs when an ALTER TABLE statement attempts to apply the PERSISTED keyword to a column that is not defined as a computed column. SQL Server only allows the PERSISTED attribute to be set or modified on columns whose values are derived from an expression (computed columns); regular data-type columns (e.g., INT, VARCHAR, DATETIME) do not support this attribute. This typically happens due to a scripting error, a migration script written for the wrong table/column, or confusion between a regular column and a computed column sharing a similar name.
Step-by-Step Resolution Guide
Step 1: Verify the Column Definition
- Run the following query to check if the target column is actually computed:
SELECT name, is_computed, definition
FROM sys.computed_columns
WHERE object_id = OBJECT_ID('YourSchema.YourTable');
- If the column does not appear in this result set, it confirms the column is a standard data column, not a computed one.
- Cross-check the table schema using SQL Server Management Studio (SSMS) by expanding Databases > YourDB > Tables > YourTable > Columns and inspecting the column’s properties pane.
Step 2: Correct the ALTER TABLE Syntax
- If you intended to modify a computed column, ensure the column name is spelled correctly and matches the one returned in
sys.computed_columns. - If you intended to persist a non-computed column, you must first redefine it as a computed column by dropping and recreating it with an expression:
ALTER TABLE YourTable DROP COLUMN YourColumn;
ALTER TABLE YourTable ADD YourColumn AS (Expression) PERSISTED;
- Note: You cannot directly convert a standard column into a computed one via a simple
ALTER COLUMNstatement; it requires a drop-and-recreate approach or a new column entirely.
Step 3: Review and Update Migration/Deployment Scripts
- Check Data-Tier Application (DACPAC) files or Entity Framework migration scripts for auto-generated
ALTER TABLE ... PERSISTEDstatements that may be referencing an outdated schema. - Open the script in a text editor or Visual Studio and search for the specific column name mentioned in the Error 4919 message to locate the faulty line.
- Update the script to target the correct computed column or remove the
PERSISTEDkeyword if persistence was applied erroneously.
Step 4: Rebuild the Column (If Required)
- If the column must be computed and persisted for indexing or performance reasons, create a new computed column rather than altering the existing one:
ALTER TABLE YourTable ADD NewColumnName AS (YourExpression) PERSISTED;
- Once validated, drop the old non-computed column and rename the new one using
sp_renameto match the original naming convention.
Alternative or Verification Steps
- Verification: Re-run the
sys.computed_columnsquery from Step 1 after applying changes; the column should now appear withis_computed = 1and thePERSISTEDflag active insys.columns(check theis_persistedfield). - Alternative: If modifying the schema is not feasible, create a non-persisted computed column instead (omit the
PERSISTEDkeyword) or use an indexed view to achieve similar performance benefits without altering the base table structure.