德比-约束 [英] Derby - constraints
问题描述
在Derby服务器中,如何使用架构的系统表中的信息来创建select语句,以便检索每个表的约束名称?
In the Derby server, how can you use the information in the system tables of the schema to create a select statement in order to retrieve the constraint names for each table?
推荐答案
相关手册是 Derby参考手册。有很多版本可用:10.13是2017年4月的最新版本,但2009年5月是10.3。
The relevant manual is the Derby Reference Manual. There are many versions available: 10.13 was current in April 2017, but it was 10.3 in May 2009.
原始答案
SELECT c.constraintname, t.tablename
FROM sysconstraints c, systables t
WHERE c.tableid = t.tableid;
由于Derby的最新版本要求系统目录表的前缀为 sys。
( kiwicomb123 用评论),您也可以修改查询以使用显式JOIN表示法,并使用:
Since sufficiently recent versions of Derby require that the system catalogue tables are prefixed by sys.
(10.13 is quoted by kiwicomb123 in a comment), you can revise the query to use the explicit JOIN notation too, and use:
SELECT c.constraintname, t.tablename
FROM sys.sysconstraints c
JOIN sys.systables t
ON c.tableid = t.tableid;
您可以添加额外的列,例如 c.type
获取约束类型。
You can add extra columns — for example, c.type
to get the constraint type.
这篇关于德比-约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!