In: Computer Science
Define database relationship and name its type?
There are mainly three types of database relationships:
One to One Relationship:
1:1 relationship implies every record in table, say A relates to only one record in other table, say B.
Example: A person has passport. There are 2 tables: person and passport. A person cna have only 1 passport. Thus, 1:1 relationship.
One to Many or Many to One Relationship:
It occurs when one record in table relates to one or more records of other table. 1:n
Example: customer has account or Student has Subjects. There are 2 tables say, Customer and account. A customer can have one or more accounts. 1:n relationship. Similar case of student and subject.
Many to Many Relationship:
It occurs when one record in first table relates to one or more records of second table and one record of second table relates to one or more records of first table. m:n relationship.
Example: Customer and Product relationship. There re 2 tables: customer and product. A customer can take one or more products. Similarly, one product can be taken by one or more customers.