Search code examples
primary-keyderby

Describe table to get the primary key for a table in Apache Derby


I am using Apache Derby 10.14.2. I need to know the primary key for a table. When I perform the Describe for the table, I only got the following instruction. derby system tables for the column of primary key info do not have an answer.

ij> create table id ( id int primary key, name varchar(10));
ij> describe id; 

COLUMN_NAME         |TYPE_NAME|DEC&|NUM&|COLUM&|COLUMN_DEF|CHAR_OCTE&|IS_NULL&
------------------------------------------------------------------------------
ID                  |INTEGER  |0   |10  |10    |NULL      |NULL      |YES     
NAME                |VARCHAR  |NULL|NULL|10    |NULL      |20        |YES

In this, no information about the primary key is given. What is the query to get the primary key of a table in Apache Derby?


Solution

  • In a program, use DatabaseMetaData.getPrimaryKeys()

    Or, if you want to run queries against the Derby system catalogs directly, you can read the answers to this related question.