sqlsql-servert-sql

sql 2005 force table rename that has dependencies


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


Solution

  • Find the "enforced dependencies", then remove or disable them.

    By "enforced dependencies", it means Schema binding, so you'll have to look specifically for that.

    Here's a query to look for schema binding references to your object:

    select o.name as ObjName, r.name as ReferencedObj
    from sys.sql_dependencies d
    join sys.objects o on o.object_id=d.object_id
    join sys.objects r on r.object_id=d.referenced_major_id
    where d.class=1
    AND r.name = @YourObjectName
    

    As I noted in the comments, there is no way to FORCE-ibly override Schema Binding. When you use Schema Binding, you are explicitly saying "Do not let me or anyone else override this." The only way around Schema Binding is to undo it, and that's intentional.