Re: One to One relationships

From: --CELKO-- <71062.1056_at_compuserve.com>
Date: 24 Apr 2003 18:06:56 -0700
Message-ID: <c0d87ec0.0304241706.7f16cd7f_at_posting.google.com>


>> If an entity must have exactly one thing what is the point in
making another entity (table) for the 'thing'? <<

It depends. Is house an entity or an attribute of a person? I'd say it is an entity and would write something like this:  

CREATE TABLE Persons
(person_id INTEGER NOT NULL PRIMARY KEY,  ...);

CREATE TABLE Houses
(house_id INTEGER NOT NULL PRIMARY KEY,
 ...);

CREATE TABLE Locations
(person_id INTEGER NOT NULL,
 house_id INTEGER NOT NULL,
 ...,
 PRIMARY KEY (person_id, house_id));

Now the *relationship* Locations can have attributes -- first year of residence or whatever makes sense.

But if we were looking at persons and genders, I'd say a gender is clearly an attribute (you don't see them floating around unattached to an entity) and should be in a column in the Persons table.

I am sure there are some fuzzy cases where entity/attribute is a coin toss, but I cannot think of one off hand.

ORM modeling will save you a lot of truble on this point. Received on Fri Apr 25 2003 - 03:06:56 CEST

Original text of this message