I have a question about design part of my db I have 3 tables like these:
CREATE TABLTE projects (
uuid uuid
name text
)
CREATE TABLTE invoices (
uuid uuid
cost text
)
CREATE TABLTE fields (
uuid uuid
parent uuid REFERENCES (???) ON DELETE CASCADE ON UPDATE CASCADE,
type varchar(255) (project or invoice)
)
is possible somehow to create one foreign key that look on more then one table and based on 2 columns (parent, type)? or do I need to do something like this?
CREATE TABLTE filds (
uuid uuid
project_uuid uuid REFERENCES projects(uuid) ON DELETE CASCADE ON UPDATE CASCADE,
invoice_uuid uuid REFERENCES invoices(uuid) ON DELETE CASCADE ON UPDATE CASCADE,
)
projects
andinvoices
, or a single table with atype
in it. The decision often depends on whether they have similar attributes or not.