gpt4 book ai didi

java - 用于禁用约束的 Informix DDL 执行

转载 作者:行者123 更新时间:2023-11-30 04:17:06 25 4
gpt4 key购买 nike

我计划禁用外键约束以避免在清除某些数据时出现递归关系。主要步骤如下:

Connection conn = getConnection(SI_SINGLE_URL2, SI_UNAME2, SI_PASS2); // will return a valid java,sql.Connection
Statement stmt = conn.createStatement();
boolean isConstraintDisabled = stmt.execute("ALTER TABLE zee_temp_tab_2 NOCHECK CONSTRAINT ALL");
stmt.executeQuery("DELETE FROM zee_temp_tab_2 WHERE id = 'A'");
boolean isConstraintEnabled = stmt.execute("ALTER TABLE zee_temp_tab_2 CHECK CONSTRAINT ALL");

请告知如何操作。

最佳答案

禁用表的所有约束(PK、唯一、非空、检查)

 set constraints for table <table> disabled;

或特定约束

 set constraints <constraint_name> disabled;

要启用,只需使用“enabled”参数。观察:所有 PK、FK 和 UNIQUE 都将重新创建内部索引...具体取决于您的记录数,可能需要一些时间...小心。

其他选项是使用“延迟”选项(这样您不需要禁用,但需要在单个事务中完成所有操作。)

set constraints <ALL|constraint_name> deferred;
begin work;
-- do what you have to do
commit work; -- the constraints will be validated here...
set constraints <ALL|constraint_name> immediate;

还有“过滤”选项...但这稍微复杂一点,需要 DBA 的支持。

有关详细信息,请在 online manual 中搜索此命令

关于java - 用于禁用约束的 Informix DDL 执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18105468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com