Yassin Hajaj
Yassin Hajaj

Reputation: 21995

UML : Optional Foreign Key

I'm sitting with a little headache about a problem right now.

I have two entities PAYMENT ORDER and ACCOUNT

PAYMENT ORDER
PK - ID
FK - DEBITED ACC
FK - CREDITED ACC


ACCOUNT
PK - ACCOUNTNUMBER

I struggle to find the logic when the credited account is not an account from my financial institution. It can not be a foreign key anymore since the account will not be contained within the ACCOUNT table.

Have you guys an idea about a workaround?

EDIT

Question is : Do I have to change the constraint on CREDITED ACC to nothing ? Or can I keep it the way it is?

Upvotes: 0

Views: 292

Answers (1)

Jim L.
Jim L.

Reputation: 6529

I recommend you make your ACCOUNT table contain more than just an ACCOUNTNUMBER column.

If this is just a toy example, add a boolean to indicate whether this account number is internal versus external. If this is going to be an operational system, consider adding a FINANCIAL_INSTITUTION table and use its primary key as a foreign key in the ACCOUNTNUMBER table.

Upvotes: 1

Related Questions