Oracle - 删除表约束而不删除表
我正在对大型 Oracle 数据库进行批量迁移。第一步涉及重命名整个表负载,为以后删除它们做准备(但我现在需要保留其中的数据)。需要删除对它们的任何外键约束 - 它们根本不应该连接到数据库的其余部分。如果我现在删除它们,我可以级联约束,但重命名只会改变约束。
有没有一种方法可以删除 CASCADE CONSTRAINTS 将删除的所有约束而不删除表本身?
I'm doing some bulk migration of a large Oracle database. The first step of this involves renaming a whole load of tables as a preparation for dropping them later (but I need to keep the data in them around for now). Any foreign key constraints on them need to be dropped - they shouldn't be connected to the rest of the database at all. If I were dropping them now I could CASCADE CONSTRAINTS, but rename simply alters the constraints.
Is there a way I can drop all of the constraints that CASCADE CONSTRAINTS would drop without dropping the table itself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用动态 SQL 和数据字典来做到这一点:
如果这些表由多个用户拥有,您将需要从 DBA_CONSTRAINTS 驱动并将 OWNER 包含在投影和执行的语句中。如果您不想接触所有表,恐怕您需要在 WHERE 子句中指定列表,除非它们的名称有某种模式。
You can do it with dynamic SQL and the data dictionary:
If the tables are owned by more than one user you'll need to drive from DBA_CONSTRAINTS and include OWNER in the projection and the executed statement. If you want to touch less than all the tables I'm afraid you'll need to specify the list in the WHERE clause, unless there's some pattern to their names.
您可以禁用/重新启用约束而不删除它们。请查看这篇文章。
You can disable/re-enable constraints without dropping them. Take a look at this article.