dbTalk Databases Forums  

1 <-> 0..1 relationship

comp.databases.theory comp.databases.theory


Discuss 1 <-> 0..1 relationship in the comp.databases.theory forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Victor Porton
 
Posts: n/a

Default 1 <-> 0..1 relationship - 12-13-2011 , 08:40 AM






I have "1 <-> 0..1 relationship". For example:

There is a set of users. Some users are customers.

Thus we have two tables: the table `users` and the table `customers`.

What is the best way to express this in a relational database:

1. In the table `users` add the `customer` field which may be either a
ref to `users` or NULL.

2. In the table `customers` add UNIQUE `user` field which refers to
`users` table.

I have already asked a similar question in some forums, but the answer
was basically "whatever you need", "whatever you think convenient". I
don't like this kind of answer. I want a serious piece of DB theory
instead, a well founded answer. Where to read about 1 <-> 0..1
relationships?

Reply With Quote
  #2  
Old   
Erwin
 
Posts: n/a

Default Re: 1 <-> 0..1 relationship - 12-13-2011 , 10:03 AM






On 13 dec, 15:40, Victor Porton <por... (AT) narod (DOT) ru> wrote:
Quote:
I have "1 <-> 0..1 relationship". For example:

There is a set of users. Some users are customers.

Thus we have two tables: the table `users` and the table `customers`.

What is the best way to express this in a relational database:

1. In the table `users` add the `customer` field which may be either a
ref to `users` or NULL.

2. In the table `customers` add UNIQUE `user` field which refers to
`users` table.

I have already asked a similar question in some forums, but the answer
was basically "whatever you need", "whatever you think convenient". I
don't like this kind of answer. I want a serious piece of DB theory
instead, a well founded answer. Where to read about 1 <-> 0..1
relationships?
There is no place for NULLs in the relational model of data.

Relational theory has very little answers to "what is the best
database design".

It also has very little to say about that thing that you call
"relationships". (E/R modeling was invented only a couple of years
after the relational model was.)

The logical structure of your data, expressed in relational terms,
seems to be :

VAR RELATION {USERID, <attribute names for user properties here>} USER
KEY {USERID};
VAR RELATION {USERID, <attribute names for customer properties here>}
CUSTOMER KEY {USERID};
CONSTRAINT ALL_CUSTOMERS_ARE_USERS CUSTOMER{USERID} SUBSETOF
USER{USERID};

This covers what you have told us about the problem.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.