1

I have a Java application that is based (JPA, spring-data) on a relational database (PostgreSQL). This database has several tables referencing a specific table. So referencial integrity kicks in, when the user likes to delete an entry in that table.

Currently I have a complicated view joining all those referencing tables to see if there are any references. If so I have additional queries (depending on the referencing tables) to show business data to the user (and a link to the corresponding UIs) so that the user can examine the referencing data.

I don't like that solution since a) it seems to be a lot of overhead for just displaying a comprehensive error message and b) it duplicates the reference-integrity check of the database.

What I would prefer is:

  • databases to have means to check referencial integrity before executing the delete
  • databases to provide information which tables/rows are referencing the data (when the error kicks in)

I am pretty sure that both is not possible (but I don't understand why databases don't have those features). Correct me if I am wrong. And if there are other possibilities / best practices, please let me know.

Sebastian
  • 877
  • 1
  • 9
  • 20
  • You might get more (than none ;-) ) answers if you limit the scope of the question. For example, to just Postgres. – Jorn Jun 22 '23 at 11:18
  • You should be able to achieve point 1 by starting a transaction and just executing the delete statement. An error will mean there are references. No error? Then just rollback the transaction. – Jorn Jun 22 '23 at 11:23

0 Answers0