Understanding Database Entities and relationships

Understanding Database Entities and relationships

The definition of an entity depends on who you ask. In Law, according to source:

Person or Entity means an individual, natural person, corporation, government or political subdivision or agency of a government, and where two or more persons act as a partnership, limited partnership, syndicate or other group for the purpose of acquiring, holding or disposing of securities of an issuer, such partnership, limited partnership, syndicate or group shall be deemed to be a Person or Entity.

Hence for this article, I’d be discussing entities in the realm of databases and software engineering.

In the technical space, we’d like to define our entities as an abstract concept that defines groups with shared attributes.

As a human being, you’d have a name, parents (who are typically other humans), date of birth, ethnicity, etc. These values are but a subset of what makes you human, they are known as the attributes of the human entity. Is there any other attribute you can think of for the human entity?

Also, an entity could depend on other entities. For example,
University is an entity with attributes name, rank, country, etc. However, a single university would be made of entities such as Faculty, Department, Professor, Student, etc.

An Online Retailer entity would depend on other entities such as Customer, Supplier, Payment Provider, etc.

So as you can see, what defines an entity would be its shared attributes. These shared attributes are specific to the use case.

Therefore, to answer the question, Am I an entity? — I’m an instance of the entity called a Human Being. If in a distant future, we perfect cloning and replicas of me are created, then we could have an entity for me as I am instantiated in other beings. We’d call the entity Dami.

To get a grasp of all I’ve written thus far, I’d recommend you take a few seconds to do a quick appreciation of the entities around you. You could add what you found to the comment section.

Entity Relationship Diagram

Having identified your entities, the next step is to design/define the relationship between them. I found that this definition helps to determine if your entity definition is accurate or if you need to go a bit granular for your model.

You could do this with a Pen on Paper or you could use a tool like draw.io. To explain this, I’d design a simplified Entity relationship diagram using draw.io for a nuclear family model.

Simplified Family Entity Relationship diagram

This is a simplified Entity Relationship diagram to illustrate the entities in a typical family and the relationship between them.

The Parent and Children entity both depend on the HumanBeing entity as every instance of Parent/Children would typically also be human. The Pets entity also depends on the HumanBeing entity because it references the owner of the pets in the family.

Difference between Entities and Objects

Entities typically represent a database schema for a table as it contains only attributes that map to columns in the table. It can not be instantiated during the runtime of a program, it’s only an abstract concept we use in guiding our design.

However, objects are data structures that can be instantiated during the runtime of a program. An Entity Object would include the attributes and the actions(defined as functions/methods in the class) for that entity.

The entity object would be covered in my next post.

Thank you for reading, I hope you’ve been able to get a better understanding of what entities are and how they differ from objects. If you have any comments/questions/additions/corrections, please feel free to drop a comment down below and I’d be sure to respond to you as soon as possible.

I typically write about my learnings as a software engineer. If you liked this article, please subscribe to my email list so you get updates when I publish new articles.