sql 2005 force table rename that has dependencies

Viewed 23126

How do you force a rename???

Rename failed for Table 'dbo.x. (Microsoft.SqlServer.Smo)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.0.2531.0+((Katmai_PCU_Main).090329-1045+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Rename+Table&LinkId=20476


An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)


Object '[dbo].[x]' cannot be renamed because the object participates in enforced dependencies. (Microsoft SQL Server, Error: 15336)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.4035&EvtSrc=MSSQLServer&EvtID=15336&LinkId=20476

5 Answers

I had the same issue , my problem was that i has a COMPUTED FIELD using the column i was trying to rename.

by running the query from the selected answer i was able to tell that had enforced dependencies, but i was not able to see exactly what was the problem

In the SQL Server Object Browser, right-click on the table with the issue and select View Dependencies. Next in the view listed, Right-click (view) and select SCRIPT to CREATE VIEW in New SQL Query Editor window, then remove WITH SCHEMABINDING from the CREATE VIEW t-sql script and run the revised CREATE VIEW t-sql. This unlinks the schema dependency from the table. I was able to recreate the table at this point (DROP, RENAME, etc).

Note:

Schema binding can occur on functions and other objects in your db. Use of View Dependencies on the object throwing the error is essential to fix the issue.

BTW:

I originally added schema binding to enable view indexing. Keeping a good index on the underlying table(s) may mitigate the performance hit of not having one on the view.

  1. View Dependencies
  2. More on Schema Binding
Related