I am just curious why do we need to use one-one, many-one or one-many and many-many in database
-
In MS SQL you cannot establish a 1:1 relationship: http://stackoverflow.com/questions/10292355/how-do-i-create-a-real-one-to-one-relationship-in-sql-server nor is it admissible to establish a foreign key constraint to enforce a many to many relationship: http://stackoverflow.com/questions/18435065/foreign-key-to-non-primary-key Yet, the use is pretty simple: it helps us understand the connections between all tables in a database: are they connected and if so, how? – Ralph Mar 18 '16 at 02:03
-
1Your question is unclear. Do you mean, why do we bother to give cardinalities? Or do you mean, why do we distinguish between those particular cases of cardinalities vs others? Or, why are tables in the database? Or, for each kind of cardinality when do we use it? Or what? Or what? – philipxy Mar 18 '16 at 07:49
2 Answers
It's all about need , in programming we need to maintain data in databases . in many situations we need to create related tables , these kind of related tables connected with relations . for example if you build a application to maintain the user contacts , then you need to design a table for user and contact . here you will be relate both the tables

- 2,338
- 19
- 24
If you mean, why do we distinguish between cardinalities of relationships, then the answer is that there is no need. All that matters is that we identify & describe sufficient relationships to describe every application situtation.
The cardinality of participation by entities in a relationship is just one property of the relationship. Eg if table EmployeeManager
holds the rows where "manager M manages employee E" then it doesn't matter to filling the table whether there is only one manager per employee or one employee per manager; you just look at the world and put the rows that make a true statement from that statement template into the table. Eg Ditto for interpreting a table: the rows are all those that make the statement template into a true statement about the world. You don't need to know cardinalites to query. Eg if table DepartmentManager
holds the rows where "manager M manages department D" then EmployeeManager NATURAL JOIN DepartmentManager
holds the rows where "manager M manages employee E AND manager M manages department D" whether or not there is only one manager per employee, or employee per manager, or manager per department, or department per manager.
But the benefits are that if we tell the DBMS then it can keep out invalid states, and if we tell users then it can help them understand what the relationship statement templates mean or why the DBMS disallowed a putative erroneous update.

- 14,867
- 6
- 39
- 83