Relationships in database management system
Relationships in Database:
A relationship is a bond between the different objects in a database.
It works by matching data in key columns usually columns with the same name in
both tables.
In most cases, the relationship matches the primary key from one table,
which is a unique identifier for each row, with an entry in the foreign key in
the other table.
There are three types of relationships between
tables:
•
One-to-One Relationship
•
One-to-Many Relationship
•
Many-to-Many Relationship
One-to-One Relationships:
In this type of relationship, a row in table A can
have no more than one matching row in table B, and vice versa. A one-to-one
relationship is created if both of the related columns are primary keys or have
unique constraints.
Example: You can consider Country and Capital City
relationship as One-to-One because one country will be associated with only one
Capital City and One Capital City will be associated with only one country.
One-to-Many Relationships
In this type of relationship, a row in table A can have many matching
rows in table B, but a row in table B can have only one matching row in table
It is the most common type of relationship.
Example: You can consider Country and City relationship as
One-to-Many because one country will be associated with many cities where as
one city will be associated with only one country
Many-to-Many Relationships
In this type of relationship, a row in table A can have many matching
rows in table B, and vice versa. You create such a relationship by defining a
third table, called a junction table, whose primary key consists of the foreign
keys from both table A and table B.
Example: You can consider Country and River as
Many-to-Many relationship because one country may have different rivers passing
through it, in the same way a river may pass through many countries
Labels: dbms relationships, differences between different relationships, relationships in database, Relationships in database management system, SQL Basics
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home