Skip to content

It is not possible to correlate DatabaseMetadata index info and primary key info for unnamed constraints #791

@prrvchr

Description

@prrvchr

There are two methods in DatabaseMetadata (getPrimaryKeys() and getIndexInfo()) which do not give the same result if we create a primary key when creating the table or if we add a primary key after creation of the table.

If we add the primary key after creating the table by the command:
ALTER TABLE "Table1" ADD CONSTRAINT "PK_Table1_ID" PRIMARY KEY ("ID");
We can find the name of the constraint created (PK_Table1_ID) in:

  • column 6 (PK_NAME) for the getPrimaryKeys() method.
  • column 6 (INDEX_NAME) for the getIndexInfo() method.

If we create the primary key when creating the table, we will not be able to name the primary key and if we try to find it using the DatabaseMetadata we will obtain:

  • INTEG_12 in the column 6 (PK_NAME) for the getPrimaryKeys() method.
  • RDB$PRIMARY9 in column 6 (INDEX_NAME) for the getIndexInfo() method.

In this case, we are unable to find the index linked to the primary key using the methods offered by DatabaseMetadata.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions