Troubleshooting Guide: SQL Server Error 4988 — “Cannot persist computed column” (Ownership Mismatch)
Why This Error Happens
This error occurs when a computed column references a function, view, or other object (via a schema-bound or deterministic expression) that is owned by a different database principal than the table itself. SQL Server requires strict owner-matching between a persisted or indexed computed column and all underlying objects it references to guarantee deterministic behavior and prevent ownership-chaining security issues. This typically happens after a schema migration, a restored database from another environment, or when objects were created by different logins/users without explicit schema alignment.
Step-by-Step Resolution Guide
Step 1: Identify the Ownership Mismatch
- Run the following query to find the owner of the table in question:
SELECT s.name AS SchemaName, t.name AS TableName, dp.name AS OwnerName
FROM sys.tables t
JOIN sys.schemas s ON t.schema_id = s.schema_id
JOIN sys.database_principals dp ON t.principal_id = dp.principal_id
WHERE t.name = 'YourTableName';
- Compare this against the owner of the referenced function/object:
SELECT o.name, o.type_desc, dp.name AS OwnerName
FROM sys.objects o
JOIN sys.database_principals dp ON o.principal_id = dp.principal_id
WHERE o.name = 'YourReferencedFunctionOrView';
- Note any discrepancy in the
OwnerNamecolumns — this is the root cause of Error 4988.
Step 2: Align Ownership Using ALTER AUTHORIZATION
- Use
ALTER AUTHORIZATIONto reassign the underlying object to match the table’s owner (or vice versa, depending on your security policy). - Example command to align a function’s owner with the table’s schema owner:
ALTER AUTHORIZATION ON OBJECT::dbo.YourReferencedFunction TO [dbo];
- If the table and function live in different schemas, consider moving the object into the same schema instead:
ALTER SCHEMA dbo TRANSFER OtherSchema.YourReferencedFunction;
- Ensure you have
CONTROLorALTERpermission on both the object and the target schema/principal before running this.
Step 3: Drop and Recreate the Computed Column
- Once ownership is aligned, drop the problematic computed column:
ALTER TABLE YourTableName DROP COLUMN YourComputedColumn;
- Recreate it with the
PERSISTEDkeyword now that ownership matches:
ALTER TABLE YourTableName
ADD YourComputedColumn AS (dbo.YourReferencedFunction(SomeColumn)) PERSISTED;
- If the column is part of an index, rebuild the index afterward:
CREATE INDEX IX_YourIndex ON YourTableName(YourComputedColumn);
Step 4: Validate Schema Consistency Server-Wide
- Run
sys.sql_expression_dependenciesto check for any other computed columns referencing cross-schema objects with mismatched ownership. - Document and standardize schema ownership (e.g., enforce all business objects under
dbo) to prevent recurrence after future deployments or restores.
Alternative or Verification Steps
- Verify the fix by querying
sys.computed_columnsand confirming theis_persistedflag is set to1for the affected column without throwing Error 4988 onALTER TABLEorINSERToperations. - If
ALTER AUTHORIZATIONis restricted by compliance policy, an alternative is to rewrite the computed column expression using only inline T-SQL logic (avoiding external function calls) so no cross-object ownership dependency exists at all.