Skip to content

DatabaseMetaData#getImportedKeys() returns wrong value for DELETE_RULE #467

@rdicroce

Description

@rdicroce

Driver version or jar name

6.1.7

SQL Server version

13.0.4001.0

Client operating system

Windows 10

Java/JVM version

Oracle 8u144

Table schema

dbo

Problem description

DatabaseMetaData#getImportedKeys() returns UPDATE_RULE and DELETE_RULE columns with incorrect values.

Expected behavior and actual behavior

For a foreign key created with ON DELETE SET NULL, the JavaDoc says DELETE_RULE should be equal to the importedKeySetNull constant, which has a value of 2. But the driver reports 1.

The cause is that the data is obtained by executing sp_fkeys on the server. sp_fkeys only returns 0 or 1 for the delete and update actions (i.e. it does not provide detail at the level of granularity required). This also affects any other APIs (e.g. getExportedKeys()) that use sp_fkeys to get their data.

Possible solutions:

  • The sys.foreign_keys table has more granular information. It could be joined to various other tables to return all of the relevant data.
  • sp_fkeys could be changed. There was an issue about this but it was closed as Won't Fix.

Metadata

Metadata

Assignees

Labels

Waiting for ResponseWaiting for a reply from the original poster, or affiliated party

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions