I am quite ashamed to ask this, but recently there has been a situation where I need to create a single table for three different types of banking entities that are related to each other. Let me explain.
Imagine a BANK table that holds details of either a Governing Bank, or a regular Bank that operates rural branches, or the rural branches operating under this Bank or Retail Bank Branches that don't fall in this hierarchy but only transact with rural branch.
Previously, I decided on having 4 different tables for these, with FK constraints (i.e one each for Governing Bank, Bank that operates rural branches, rural branch and Retail Bank Branch). But when I moved on to create the TRANSACTION table I was perplexed since transactions could happen between any of these entities (example: between rural branch & Retail Branch, between rural branches themselves etc). This meant that I would not only have to keep a record of the "Source" & 'Destination" IDs of the Banking Entity, but also keep some data to help the application logic determine which TABLE to JOIN on for querying. I felt that was bad.
Moreover, there is a USER table and the user could belong to any of these entities, here too having 4 different tables of banking entities was problematic. How do I know if the User belongs to a rural branch or Retail Branch or the Governing bank?
Therefore, I created a single BANK table (essentially because they are similar entities, as they can transact with each other). I added a PARENT column in the table that would hold the value of ID of the parent institution (relationship I otherwise achieved using FKs). So a rural branch will have ID of Operating Bank in its parent column. Retail branches have no parents hence the value is NULL there and so on.
The problem I see now is that there is a PK/FK relationship in the BANK table, a cyclic reference.
My question is is: how bad is this? And what could be a way out?