sql 2005 force table rename that has dependencies

后端 未结 5 1812
一个人的身影
一个人的身影 2020-12-28 14:59

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+

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-28 15:45

    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.

提交回复
热议问题