java – 通过JDBC删除Derby中的所有约束

前端之家收集整理的这篇文章主要介绍了java – 通过JDBC删除Derby中的所有约束前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如何通过JDBC删除Derby数据库中的所有约束?

最佳答案
您可以查询系统表SYS.SYSCONSTRAINTS,SYS.SYSTABLES和SYS.SYSSCHEMAS以获取给定模式的所有约束名称和相关表.

首先,关于这些表的几句话(从Re: System tables in Derby开始):

SYSTABLES has one row for each table in the database. Its primary key is TABLEID,which contains system-generated values. The SCHEMAID is a foreign key column,which references SYSSCHEMAS.

SYSSCHEMAS has one row for each schema in the database. Its primary key is SCHEMAID.

SYSCONSTRAINTS has one row for each constraint in the database (primary,unique,foreign and check constraints). Its primary key is CONSTRAINTID,which is a system-generated value. The TABLEID column is a foreign key referring to SYSTABLES.TABLEID. The SCHEMAID column is a foreign key referring to SYSSCHEMAS.SCHEMAID.

所以你可以使用以下查询

SELECT 
    C.CONSTRAINTNAME,T.TABLENAME 
FROM 
    SYS.SYSCONSTRAINTS C,SYS.SYSSCHEMAS S,SYS.SYSTABLES T 
WHERE 
    C.SCHEMAID = S.SCHEMAID 
AND 
    C.TABLEID = T.TABLEID
AND 
    S.SCHEMANAME = 'MYSCHEMA';

然后循环并构建相应的ALTER TABLE DROP CONSTRAINT语句.

参考

> Derby support for SQL-92 features

>表22.对sql-92功能支持:约束表

> Re: System tables in Derby

原文链接:https://www.f2er.com/java/437716.html

猜你在找的Java相关文章