sql 2005 强制重命名具有依赖项的表

sql 2005 强制重命名具有依赖项的表

问题描述:

你如何强制重命名???

How do you force a rename???

重命名表 'dbo.x 失败.(Microsoft.SqlServer.Smo)

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

如需帮助,请点击: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&6LinkIda>

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

执行 Transact-SQL 语句或批处理时发生异常.(Microsoft.SqlServer.ConnectionInfo)

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

对象[dbo].[x]"无法重命名,因为该对象参与强制依赖.(Microsoft SQL Server,错误:15336)

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

如需帮助,请单击:http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.4035&EvtSrc=MSSQLServer&EvtID=15336&LinkId=20476>

找到强制依赖项",然后删除或禁用它们.

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.