This is the simplest mapping between two objects.
For example: every person has a unique finger-print.
So if person and finger-prints are two separate tables in a database, then it can be said that those two tables have a one-to-one mapping.
Typically, one-to-one mapping fields are recommended to be put in the same table to avoid costly joins when reading.
Consider an author who has written several books.
If authors and books are kept in two tables, then there is a one to many mapping from author table to book table.
Such a relationship is stored using:
A third table storing author-id vs book-id.
Storing a foreign key, such as author-id in book table.
This is just the inverse of the one-to-many mapping.
For instance, in the above case, book table has many-to-one mapping with the author table.
Consider a relationship between a person and the types of car owned by him.
Clearly, it is a one-to-many relationship because a single person can own different types of cars like sedan, coupe etc.
But the relationship is one-to-many from car-type table to persons table also because a given car-type can be owned by many individuals.
Example, sedan can be owned by more than one persons.
Thus, in such a case, there exists a many-to-many relationship between person and car-type table.
Knowing the type of relationships between table formalizes the relationship and makes it easier to describe.
Got a thought to share or found a bug in the code? We'd love to hear from you: