Derby - constraints

前端 未结 2 1949
傲寒
傲寒 2021-01-13 07:51

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

2条回答
  •  时光说笑
    2021-01-13 08:45

    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.

    Original answer

    SELECT c.constraintname, t.tablename
        FROM sysconstraints c, systables t
        WHERE c.tableid = t.tableid;
    

    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;
    

    You can add extra columns — for example, c.type to get the constraint type.

提交回复
热议问题