- need to design database tables to manage account and customer.
- 1 Account can have 1 Primary Holder but zero or more Joint holders.
- Accounts and Customers can be linked using Link table.
Question - where can Primary Account Holder information be kept for above requirements ?
I have put few thoughts below but I am not if they are in right direction.
Is there another solution I can use ?
Solution 1: Keep IsPrimary column in link table to show which customer is PrimaryHolder.
Issue - NO way to control this to 1 row. By mistake 2 customers could be marked primary for any account.
create table Accounts (
AccountId INT
)
create table Customers (
CustomerId INT
)
create table AccCustLink (
AccCustLinkId INT,
AccountId INT,
CustomerId INT,
IsPrimary BOOLEAN // this shows if customer is primary
)
Solution 2: Keep Primary Holder in main table. Use link table for only Joint Account Holders.
Issue - "Account - Client" link is split across muliple tables and 2 tables have information around which clients are associated with an account.
create table Accounts (
AccountId INT,
PrimaryCustomerId INT, // this has primary holder id and will be restricted to one data point.
PRIMARY(AccountId)
)
create table Customers (
CustomerId INT
)
create table AccJointHolders (
AccCustLinkId INT,
AccountId INT,
CustomerId INT // only joint account holders will be present in this table.
)
CodePudding user response:
Solution 2 in my opinion as long as there is a unique constraint on account I’d in accounts table . So no 2 people can become primary account holder accidentally