I have an ASSETS table that has a structure as shown below:
---------------------------------------------------- ID (PK) | DESCRIPTION | TYPE | Do- | Do+ | Dx- | Dx+ ----------------------------------------------------
Column
TYPE has a foreign key, possible values ββare SECURITY or CURRENCY (i.e. FX), also I have two more tables: CURRENCIES (e.g. EUR , RUB or USD ):
and SECURITIES (e.g. MTS , GAZP or VTB ):
How can I make a constraint that not only acts as a foreign key in CURRENCIES.FROM , CURRENCIES.TO and SECURITIES.CURRENCY , but also checks if the ASSETS.TYPE link ASSETS.TYPE CURRENCY , and in SECURITIES also checks if the ASSETS.TYPE link for SECURITIES.ID equal to SECURITY ?
I think I can write triggers to check the value of ASSETS.TYPE , but now I'm looking for a different solution (if possible, of course).
If there are better ways to do what you need (like a better database design), share your ideas.
PS I suppose this is a fairly common problem, so if you have articles about it or similar questions asked on this network or some general solutions, feel free to share.
source share