I have a database schema that includes the following tables:
- People
- Organisations
- RelationshipTypes
What I want to design is a concept of a relationship type, and then the structure of that relationship. So a person could have a type of relationship with another person or with an organisation. An organisation can have a relationship with another organisation or a person.
I've got the following schema, but I'd like to run it past the community to see if there are any better ideas.
CREATE TABLE OrganisationRelationshipTypes
(
ID INT PRIMARY KEY IDENTITY,
RelationshipTypeID INT NOT NULL REFERENCES RelationshipTypes(ID)
FromOrganisationID INT NOT NULL REFERENCES Organisations(ID),
ToOrganisationID INT NOT NULL REFERENCES Organisations(ID)
)
CREATE TABLE PersonRelationshipTypes
(
ID INT PRIMARY KEY IDENTITY,
RelationshipTypeID INT NOT NULL REFERENCES RelationshipTypes(ID),
FromPersonID INT NOT NULL REFERENCES People(ID),
ToPersonID INT NOT NULL REFERENCES People(ID)
)
CREATE TABLE OrganisationPersonRelationshipTypes
(
ID INT PRIMARY KEY IDENTITY,
RelationshipTypeID INT NOT NULL REFERENCES RelationshipTypes(ID)
FromOrganisationID INT NOT NULL REFERENCES Organisations(ID),
ToPersonID INT NOT NULL REFERENCES People(ID)
)
CREATE TABLE PersonOrganisationRelationshipTypes
(
ID INT PRIMARY KEY IDENTITY,
RelationshipTypeID INT NOT NULL REFERENCES RelationshipTypes(ID)
FromPersonID INT NOT NULL REFERENCES People(ID),
ToOrganisationID INT NOT NULL REFERENCES Organisations(ID)
)
The idea of this is that it covers such scenarios:
- An organisation has done business with another organisation
- A person is another person's father
- An organisation recently hired the person
- A person recently worked for the organisation
This schema seems a little messy, but at the minute I can't think of an alternative.
Do you have any suggestions?