Sample Header Ad - 728x90

SQL: Entity belongs (many-to-one) one of two different entities

0 votes
1 answer
806 views
Let's say I have organization and person and they have a one-to-many relationship with post. post could only be owned by either an organization or user (person). What I'm doing right now is making the foreign key nullable and adding a check constraint to ensure only one of organization_id and person_id has a value and the other one is null. Is this considered a valid SQL design (best practise)? What if I had more than two entities that could be the owner of a certain post? enter image description here
Asked by Yousif (27 rep)
Oct 8, 2021, 09:20 PM
Last activity: Jul 31, 2024, 12:43 PM