Types of Relationships in SQL Server

Types of Relationships:
There are three relationships available between the tables and are discussed as follows:

One-To-One Relationships:
A one-to-one relationship is created if both of the related columns are primary keys or have unique constraints.
Example:
To illustrate the one-to-one relationship, imagine that in our example bank database there is a table that holds PIN numbers for ATM cards, keeping them completely separate from the remainder of the customer records (see Figure 3-1). In most cases, there would be one PIN number record for each customer record, but there may be exceptions—for instance, a high interest deposit account may not have a card, and therefore there would be no associated PIN number record.

One-To-Many Relationships:
A one-to-many relationship is the most common type of relationship. 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 A.
Example:
Using our banking example, say we have a customer master record along with any number of associated transaction records. The number of these transaction records could range from none, which corresponds to when a customer is new to the bank and hasn’t made a deposit or performed a transaction, to one or more, which corresponds to when there has been an initial deposit in an account, and then further deposits or withdrawal transactions after that.

Many-To-Many Relationships: 
In a many-to-many relationship, a row in table A can have many matching rows in table B, and vice versa.
Example:
An example of a many-to-many relationship might be where a company has several depots for dispatching goods, seen as the master table, which then dispatch goods to many stores, seen as the child, The depots could be located and organized so that different depots could all supply the same store, and they could be arranged in groups of produce, frozen, perishables, and bonded. In order for a store to be supplied with a full complement of goods, it would need to be supplied by a number of different depots, which would typically be in different locations.

0 comments:

Post a Comment

Blogger news