Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 491
Scott Kramer Avatar asked Oct 08 '09 23:10

Scott Kramer


People also ask

How do you change the name of a table from Oldname to Newname?

To rename a table in Oracle SQL, use the ALTER TABLE statement, in the same way as MySQL and PostgreSQL: ALTER TABLE old_name RENAME TO new_name; You simply add in your current table name and the new table name and run the command. There's no need to specify the schema name.

What is Sp_rename in SQL Server?

sp_rename automatically renames the associated index whenever a PRIMARY KEY or UNIQUE constraint is renamed. If a renamed index is tied to a PRIMARY KEY constraint, the PRIMARY KEY constraint is also automatically renamed by sp_rename . sp_rename can be used to rename primary and secondary XML indexes.


2 Answers

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.

like image 94
RBarryYoung Avatar answered Nov 07 '22 15:11

RBarryYoung


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

like image 37
Yonatan Tuchinsky Avatar answered Nov 07 '22 15:11

Yonatan Tuchinsky