如何判断HSQLDB中定义了哪些外键?
我从文档中得到的最好的是:
select * from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS;
但这只给了我以下内容。
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME UNIQUE_CONSTRAINT_CATALOG UNIQUE_CONSTRAINT_SCHEMA UNIQUE_CONSTRAINT_NAME MATCH_OPTION UPDATE_RULE DELETE_RULE
------------------ ----------------- --------------- ------------------------- ------------------------ ---------------------- ------------ ----------- -----------
PUBLIC PUBLIC SYS_FK_10078 PUBLIC PUBLIC SYS_PK_10029 NONE NO ACTION CASCADE
PUBLIC PUBLIC SYS_FK_10079 PUBLIC PUBLIC SYS_PK_10029 NONE NO ACTION NO ACTION
PUBLIC PUBLIC SYS_FK_10080 PUBLIC PUBLIC SYS_PK_10071 NONE NO ACTION CASCADE
PUBLIC PUBLIC SYS_FK_10116 PUBLIC PUBLIC SYS_PK_10071 NONE NO ACTION CASCADE
PUBLIC PUBLIC SYS_FK_10120 PUBLIC PUBLIC SYS_PK_10029 NONE NO ACTION CASCADE
PUBLIC PUBLIC SYS_FK_10124 PUBLIC PUBLIC SYS_PK_10029 NONE NO ACTION NO ACTION
PUBLIC PUBLIC SYS_FK_10128 PUBLIC PUBLIC SYS_PK_10071 NONE NO ACTION CASCADE
PUBLIC PUBLIC SYS_FK_10131 PUBLIC PUBLIC SYS_PK_10071 NONE NO ACTION CASCADE
我需要知道哪些表和列分配了外键,我需要能够删除它们。
答案 0 :(得分:6)
您可以将以下选项与REFERENTIAL_CONSTRAINTS视图结合使用:
select * from information_schema.constraint_column_usage
select * from information_schema.constraint_table_usage
或者,INFORMATION_SCHEMA.SYSTEM_CROSSREFERENCE视图是外键,其表和列的自包含视图。
请参阅http://hsqldb.org/doc/2.0/guide/databaseobjects-chapt.html#dbc_information_schema以获取列表。