Online Shopping : Computers : Databases

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

10 of 13 people (77%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

Database: Data structure: Which are main database relation types, using arrays? [one/many/graph]

Jul 6th, 2008 13:33
Knud van Eeden, dman,


----------------------------------------------------------------------
--- Knud van Eeden --- 12 September 2004 - 04:00 pm ------------------
Database: Data structure: Which are main database relation types, 
using arrays? [one/many/graph]
---
   +------+-------------+---------------+
   |      |             |               |
   |      | ONE         |  MANY         |
   |      |             |               |
   +------+-------------+---------------+
   |      |             |               |
   | ONE  | one to one  |  one to many  |
   |      |             |               |
   +------+-------------+---------------+
   |      |             |               |
   | MANY | many to one |  many to many |
   |      |             |               |
   +------+-------------+---------------+
---
Here totally 2 x 2 = 4 possibilities:
---
1. One to one
one-to-one relationship: there is exactly one row in column 1 that
corresponds to exactly one row in column 2 (and vice-versa)
  column 1         column 2
    [A] ----->     [v]
    [B] ----->     [w]
    [C] ----->     [x]
    [D] ----->     [y]
    ...            ...
---
e.g.
one person has only one birthday
So if you put persons (e.g. 'Vanessa') in 1 column, and their
corresponding birthday ('1 January 1996') in another column, then the
total amount of rows in both columns has to be equal, thus a one to one
relationship.
  column 1         column 2
    [Vanessa] -->  [1 January 1996]
    [John]    -->  [10 July 1994]
    [Marilyn] -->  [3 June 1998]
    ...            ...
---
e.g.
one product has a unique product number
So if you put products (e.g. 'Intel chip 80686') in 1 column, and their
corresponding product number ('80686-2004-1') in another column, then 
the
total amount of rows in both columns has to be equal, thus a one to one
relationship.
  column 1                  column 2
    [Intel chip 80686] -->  [80686-2004-1]
    [Intel chip 80586] -->  [80586-2004-1]
    [Intel chip 80486] -->  [80486-2004-1]
    ...            ...
---
---
2. One to many
one-to-many relationship: each row in column 1 may have many linked
rows in column 2 (but each row in column 2 may have only one
corresponding row in column 1)
  column 1         column 2
    [A] --+-->     [v]
    [B]   |        [w]
    [C]   +-->     [x]
    [D]   +-->     [y]
    ...            ...
---
e.g.
one book can have many authors
So a one to many relationship.
So if you put booktitles (e.g. 'professional JavaScript') in 1 column,
and their corresponding authors ('Nigel McFarlane', 'Andrea Chiarelli',
'James De Carli', 'Sing Li', 'Mark Wilcox', 'Paul Wilton',
'Cliff Wootton', 'Stuart Updegrave') in another column, with a number
pointing to the row of the author, this will be a one to many 
relationship.
 column 1                             column 2
 [professional JavaScript] --+-->     [Nigel McFarlane]
                             |-->     [Andrea Chiarelli]
                             |-->     [James De Carli]
                             |-->     [Sing Li]
                             |-->     [Mark Wilcox]
                             |-->     [Paul Wilton]
                             |-->     [Cliff Wootton]
                             +-->     [Stuart Updegrave]
---
one product can have many documentation files
So a one to many relationship.
So if you put the product (e.g. 'Intel chip 80686') in 1 column,
and their corresponding documentation files
('documentation filename1', 'documentation filename2',
'documentation filename3') in another column, with a number
pointing to the row of the product, this will be a one to many 
relationship.
 column 1                             column 2
 [Intel chip 80686]        --+-->     [documentation filename1]
                             |-->     [documentation filename2]
                             +-->     [documentation filename3]
---
---
3. Many to one
many-to-one relationship: each row in column 2 may have many linked
rows in column 1 (but each row in column 1 may have only one
corresponding row in column 2)
  column 1         column 2
    [A] -+--->     [v]
    [B]  |         [w]
    [C] -+         [x]
    [D] -+         [y]
    ...            ...
---
Note:
Many to one and one to many are each others reflection.
---
e.g.
many authors can work on one book
So a many to one relationship.
So if you put the authors in one column (e.g. 'Nigel 
McFarlane', 'Andrea Chiarelli',
'James De Carli', 'Sing Li', 'Mark Wilcox', 'Paul Wilton',
'Cliff Wootton', 'Stuart Updegrave'),
and the book title (e.g. 'professional JavaScript') in another column,
thus a many to one relationship.
 column 1                              column 2
 [Nigel McFarlane]      --+--------->  [professional JavaScript]
 [Andrea Chiarelli]     --+
 [James De Carli]       --+
 [Sing Li]              --+
 [Mark Wilcox]          --+
 [Paul Wilton]          --+
 [Cliff Wootton]        --+
 [Stuart Updegrave]     --+
---
---
4. Many to many
Many-to-many relationships: each row in column 1 may have
many linked rows in column 2 and vice-versa.
  column 1         column 2
    [A] <-+-->     [v]
    [B]   +        [w]
    [C]   +-->     [x]
    [D] <-+        [y]
    ...            ...
---
e.g.
many people do know many other people (but not always vice-versa,
e.g. Vanessa may know Arnold Schwarzenegger, but Arnold usually
does not know her)
So a many to many relationship.
---
the URL links on Internet pages
(this page can have links to many other pages.
And vice versa, many other pages can have links to this page).
---
---
Note:
Many to many database:
The entire Web is a graph
When we browse the Web, we encounter documents that contain references
(links) to other documents and we move from document to document by
clicking on the links. The entire Web is a graph, where the items are
documents and the connections are links. Graph-processing algorithms
are essential components of the search engines that help us locate
information on the Web.
[book: source: author: Sedgewick, Robert  - title: Algorithms in Java, 
Third Edition]
---
---
Internet: see also:
---
Database: Link: Overview: Can you give me an overview of links?
http://www.faqts.com/knowledge_base/view.phtml/aid/33838/fid/132
----------------------------------------------------------------------