SQL Server Error 1739: Fix Alter Table Failed Error
In this article
SQL Server Error 1739 occurs when you attempt to modify a table (usually via an ALTER TABLE command) that is currently being referenced by a schema-bound object. To resolve this, you must identify the dependent object—such as a schema-bound view, a check constraint, or a user-defined function—drop that object, perform your table alteration, and then recreate the object. This error is a safeguard to ensure that changes to a table's structure do not break the logic of other database objects that rely on a fixed schema.
What You'll Need
- SQL Server Management Studio (SSMS) or another SQL query editor.
- Permissions to view system catalogs (sys.sql_expression_dependencies).
- ALTER and DROP permissions on the table and the dependent objects.
- A full backup of the database before making structural changes to production data.
Step-by-Step
-
Identify the Dependent Object:
The error message usually indicates that the table has a dependency, but it may not always name the specific object. You need to query the system views to find out exactly what is blocking the ALTER command. Run the following query, replacing 'YourTableName' with the name of your table:
Look specifically for objects created WITH SCHEMABINDING. These are the primary culprits for Error 1739.SELECT referencing_id, OBJECT_NAME(referencing_id) AS ReferencingObject, o.type_desc AS ObjectType FROM sys.sql_expression_dependencies d JOIN sys.objects o ON d.referencing_id = o.object_id WHERE referenced_entity_name = 'YourTableName'; - Script the Dependent Object: Before you delete the dependent object, you must save its definition so you can recreate it later. In SSMS, right-click the identified object (e.g., the View or Function) in the Object Explorer, select Script Object as > CREATE To > New Query Editor Window. Save this script as a .sql file or keep it open in a tab.
-
Drop the Dependent Object:
Once you have the backup script, remove the dependency. If it is a view, use:
If it is a function, use:DROP VIEW dbo.YourViewName;
If the dependency is a check constraint, you will useDROP FUNCTION dbo.YourFunctionName;ALTER TABLE YourTableName DROP CONSTRAINT ConstraintName;. -
Execute the ALTER TABLE Command:
Now that the schema-bound lock is removed, run your original command to modify the table. For example, if you were trying to change a data type:
Because the dependent object is gone, SQL Server will no longer throw Error 1739.ALTER TABLE YourTableName ALTER COLUMN YourColumnName VARCHAR(100); - Recreate the Dependent Object: Execute the script you saved in Step 2. If you changed a column name or data type that the view or function relies on, you must first edit the script to reflect the new table structure. If you do not update the script, the CREATE command will fail because the underlying table no longer matches the expected schema.
- Verify the Fix: Run a SELECT query against the recreated view or execute the function to ensure that the data is flowing correctly and that the table modification did not cause logic errors in the dependent object.
Common Mistakes
One of the most frequent mistakes is attempting to use ALTER VIEW to remove schema binding without actually dropping the view. While some modifications are possible, the most reliable way to clear the 1739 error is a full DROP and CREATE cycle. Another common error is forgetting to script the object before dropping it. In complex environments, views and functions can have hundreds of lines of logic; if you drop them without a backup, you may find it impossible to recreate the exact logic manually.
Users also frequently overlook the fact that multiple objects might be bound to the same table. If you drop one view and the ALTER TABLE command still fails with Error 1739, it means there is another schema-bound object you missed. Always check the results of the dependency query thoroughly to ensure all referencing IDs are handled.
Finally, some administrators attempt to disable the schema binding globally or through server settings. This is not possible. Schema binding is a per-object property designed to maintain data integrity; it cannot be "turned off" for the whole server to facilitate a quick table change.
Tips
To avoid this issue in the future, evaluate whether you truly need WITH SCHEMABINDING. Schema binding is useful for creating indexed views (which require it) or ensuring that a table cannot be accidentally changed in a way that breaks a critical function. However, if the table structure is expected to evolve frequently, avoid using schema binding unless it is strictly required for performance indexing.
When working in a production environment, wrap your DROP, ALTER, and CREATE steps into a single transaction. This ensures that if the recreation of the view fails, the table change is rolled back, and the view is restored, preventing a period of downtime where the application cannot access the view.
Use a naming convention for your schema-bound objects. If you prefix your indexed views with idx_vw_, it becomes much easier to identify them during a dependency audit when you are troubleshooting structural errors.
Troubleshooting
If the dependency query returns no results but you are still receiving Error 1739, check for foreign key constraints. While foreign keys usually trigger different error codes, certain complex constraints or triggers can occasionally interfere with specific types of ALTER operations. Ensure that no other sessions are holding a lock on the table by running sp_who2 or checking sys.dm_tran_locks.
If you encounter a "Permission Denied" error when trying to drop the dependent object, you may be operating under a limited user role. You will need to request db_owner permissions or have a sysadmin execute the drop/create sequence. If the object is owned by a different schema, ensure you are using the fully qualified name (e.g., DROP VIEW Sales.v_OrderSummary instead of just DROP VIEW v_OrderSummary).
If the recreation of the view fails after the table alteration, check for data type mismatches. For example, if you changed a column from INT to BIGINT, and the view performs a calculation that expects a specific precision, you may need to explicitly CAST or CONVERT the column within the view definition to maintain compatibility.
Frequently Asked Questions
What exactly is schema binding?
Schema binding is a mechanism in SQL Server that locks the schema of the underlying tables referenced by a view or function. This prevents any changes to those tables that would invalidate the object, ensuring that the object always has a valid structure to query.
Can I change a column name without dropping the view?
No. If a view is created WITH SCHEMABINDING, you cannot rename, drop, or change the data type of any column referenced by that view. You must drop the view first.
Does this error happen with standard views?
No. Standard views (created without the SCHEMABINDING keyword) do not prevent table alterations. However, standard views can become "stale" or broken if the underlying table changes, which is why schema binding is used to prevent that scenario.
How do I find all schema-bound objects in my database?
You can query sys.sql_modules and look for the is_schema_bound column. A value of 1 indicates that the object is schema-bound.
Will dropping the view delete the data in the table?
No. Dropping a view, function, or constraint only removes the logic layer or the rule. It has no effect on the actual data stored within the underlying tables.
Is there a way to avoid dropping and recreating every time?
The only way to avoid this cycle is to remove the WITH SCHEMABINDING clause from the object definition. If you do not need an indexed view, removing schema binding allows you to alter tables freely, though you lose the structural guarantee.