Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differentiation between 'Entity' and 'Table'

Tags:

database

Can someone tell me the easy way to explain the differentiation between an entity and a table in database?

like image 759
Nico Avatar asked Mar 16 '23 15:03

Nico


2 Answers

Entity is a logical concept of relational database model. And table is used to express it, but there is a slight difference. Table expresses not only entities, but also relations.

For example, assume that you want to make a database of projects and employees of a company. Entity is a unit of information that has meanings by itself. In this case, there will be two entities - "Project" and "Employee". Each entity has its own attributes.

In relational DB model, there is another idea, 'relation'. If employees participate in several projects, then we can say that there is a relation with a name 'works_on'.

Sometimes, relation can have its own attribute. In this case, 'works_on' relation can have attribute 'start_date' and so on. And if this relation is M:N relation(Like this case: In project 1, there are 5 employees. Employee A works on two projects.), then you have to make an extra table to express this relation. (If you don't make an extra table when the relation is M:N, then you have to insert too many duplicated rows into both 'Project' and 'Employee' table.)

CREATE TABLE works_on(
  employee,
  project_id,
  start_date
)
like image 168
jungyh0218 Avatar answered Mar 28 '23 14:03

jungyh0218


An entity resides in a table, it is a single set of information, i.e: if you have a database of employees, then an employee is an entity. A table is a group of fields with certain parameters.

Basically everything is stored in a table, entities goes into tables.

like image 36
Luffy Avatar answered Mar 28 '23 14:03

Luffy