Database : what design to point on two possibilities?

后端 未结 3 545
执念已碎
执念已碎 2021-01-24 09:25

I am designing a datamodel for a new project.

One of the requirements specifies that some objects can point either a person or a company.

What is the sma

3条回答
  •  不思量自难忘°
    2021-01-24 09:57

    It is hard to really give an answer to this, but I'd have some notes that might be useful to you.

    But they are just some notes really.

    Overall this data model seems fine given what is known.

    • Actor type doesn't necessarily need to be another table. It could just be a coded value on this table for example.
    • As noted in other comments the actor type table is not technically required if the actor can only ever point to the two things - but I'd probably still use it as it is easier to maintain and more readable in the long term for future maintainers of the code/sql/database. i.e. the presence of the field to indicate type adds value in human readability of the code/sql and the model even if the machine doesn't need it.
    • Thinking about the evolution of the database, one thing to consider, do you think it will always just be person/company or may there in the future be different types. If it is likely to be additional actor types in the future, it is worth considering now whether factoring the actor_type and id to a link table might be useful to limit the evolution of the schema for this table.

提交回复
热议问题