CHAPTER 2Entities and Relations
Relations
In mathematics, a relation between sets A, B, C and D is a subset of the Cartesian Product of those sets. An element of the Cartesian Product of A, B, C and D contains tuples with elements from each of those sets.
A table in a relational database is, in fact, a mathematical relation. Every row is a tuple and it stores a different value for each column, of a certain type.
Entites are things, and are stored as rows in tables (or documents in DocDBs). Columns in the table are all the values of a certain attribute of each entity. The schema defines, therefore, the columns (attributes that all entities have).
Entities
Entities are usually real-world things that we want to model in the database: people, objects, events, organizations, etc. Given a "domain" (the conceptual area which a certain system occupies), it is usually relatively easy to enumerate many of its entities (doing so exhaustively and precisely is more difficult).
Examples:
- Shopping App: Products, Manufacturer, Users, Purchases, Invoices, Payments, Shopping Carts, Catalogs, ...
- Health App: Hospitals, Doctors, Patients, Tests, Visits, Payments, Appointments, ...
- Entertainment App: Movies, Actors, Reviews, Comments, Series, Episodes, Votes, ...