Nico
Nico

Reputation: 343

Differentiation between 'Entity' and 'Table'

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

Upvotes: 12

Views: 30152

Answers (4)

Joe Avan
Joe Avan

Reputation: 1

There is little difference between an entity and a table, but first we should define the concepts of “tuple” and “attribute”. I want to express those concepts with a table.

enter image description here

Here is an example of a table. As you can see it has some columns. Each column represents an attribute and each line represents a tuple(row). This is the employee table. In this example, the table is being used for representing an entity which is employee. However, if we create a new table named superior to specify the superiority relationship between those employees, it would be a table that represents a relation. In summary, we can use tables for representing both the entities and relations so entities and tables are not the same.

Upvotes: 0

Luffy
Luffy

Reputation: 1335

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.

Upvotes: 7

jungyh0218
jungyh0218

Reputation: 568

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
)

Upvotes: 17

Christian Amado
Christian Amado

Reputation: 943

In a relational database the concept is the same. An entity is a table.

In OOP (Oriented Object Programming) there is a nice article in Oracle docs:

In general terms, entity objects encapsulate the business policy and data for

the logical structure of the business, such as product lines, departments, sales, and regions

business documents, such as invoices, change orders, and service requests

physical items, such as warehouses, employees, and equipment

Another way of looking at it is that an entity object stores the business logic and column information for a database table (or view, synonym, or snapshot). An entity object caches data from a database and provides an object-oriented representation of it.

Depending on how you want to work, you can create entity objects from existing database tables (reverse generation) or define entity objects and use them to create database tables (forward generation).

Upvotes: 1

Related Questions