optionality and cardinality moving from from ERD to TABLES.

From: Andrea Fare' <fardrum_at_hotmail.com>
Date: Wed, 26 Sep 2001 21:13:02 -0700
Message-ID: <c4vs7.19149$Df4.1983956_at_news20.bellglobal.com>



I am a beginner in database design and I am experiencing some problems trying to translate with accuracy an ERD into code.

Let's say I have two entities CAR and PERSON and the following relationships exist between them:

 each CAR MUST be property of one and only one PERSON.  each PERSON MAY own one or more CARs.

Now as soon as I start creating the tables it seems logical to me to put a foreign key
in the CAR table that references the primary key in the PERSON table. Because each CAR MUST be property of one and only one PERSON it seems also logical that the foreign key in the CAR table will not be allowed to have NULL values,but how do I enforce the condition that each PERSON MAY HAVE a car, or in other words what do I have to put in my tables to make a distinction between this situation and a situation in which each PERSON MUST have a CAR?( this last sentence could be translated in to a condition that says that each entry in PERSON TABLE must be referenced at least one time in the foreign key field of the CAR table).

Should this be done at the table (creation) level and how? Any good URLs to further investigate these concepts

Thanks for Your attention.

Any good URLs to further investigate these concepts will be truly appreciated.

ANDREA. Received on Thu Sep 27 2001 - 06:13:02 CEST

Original text of this message