i want the column which is a foreign key to refer to a table conditionally, Im using psql database,
sample
id ( primary key not null )
A (id references table A.id nullable)
B (id references table B.id nullable) // both cannot be null and only A or B //can have value
externalRef (enum of varchar stores A | B)
currently in my sample table i have 2 columns A and B but tomorrow if i want to add C, D, E so on i have to create those columns too, how can i solve this and make it better ?
I have a vague idea about the solution but not sure if its implementable ?, so i wanna keep 2 columns one will be type
and other will the the refid
(refid will be the foreign key column that will refer to table that type
has)
How can i add this condition ??