views:

1171

answers:

2

I continue to get this error:

Object '%s' cannot be renamed because the object participates in enforced dependencies

I need to find a script that will help me to find all the dependencies that there is with this table. I will need to drop them, rename, then bring them back.

Thanks.

SQL Server 2005

+2  A: 

To disable all contraints

sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
go
sp_msforeachtable "ALTER TABLE ? DISABLE TRIGGER  all"
go

To Re-enable

sp_msforeachtable"ALTER TABLE ? CHECK CONSTRAINT all"
go
sp_msforeachtable "ALTER TABLE ? ENABLE TRIGGER  all"
go

You should easily be able to adapt this to just one table.

Craig
A: 

This posting contains a db reverse engineer script that I originally wrote for SQL Server 2000 and ported to 2005. If you look at the bit that does foreign key relationships you can see how to get the dependencies from the data dictionary.

ConcernedOfTunbridgeWells