SQL Server 2005,需要脚本来检查表上的所有约束

发布于 2024-07-06 15:37:08 字数 212 浏览 4 评论 0原文

我继续收到此错误:

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

我需要找到一个脚本来帮助我找到此表的所有依赖项。 我需要删除它们,重命名,然后将它们带回来。

SQL Server 2005

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.

SQL Server 2005

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

世界等同你 2024-07-13 15:37:08

禁用所有限制

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

重新启用

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

您应该能够轻松地将其调整为仅适用于一张表。

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.

情话已封尘 2024-07-13 15:37:08

这篇文章包含我最初为 SQL Server 2000 编写的数据库逆向工程脚本并移植到 2005。如果您查看处理外键关系的部分,您可以看到如何从数据字典中获取依赖关系。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文