dbTalk Databases Forums  

Simple database design question

comp.databases.theory comp.databases.theory


Discuss Simple database design question in the comp.databases.theory forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mark S. (UK)
 
Posts: n/a

Default Simple database design question - 09-30-2008 , 10:07 AM






Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Message-ID: <CtmdncWgM5g03X_VnZ2dnUVZ8trinZ2d (AT) pipex (DOT) net>
Lines: 53
X-Usenet-Provider: http://www.giganews.com
NNTP-Posting-Host: 84.12.11.241
X-Trace: sv3-t1iKYIFQX2noV2PHZLpU9xaqiEmLzL/2pMp9y0Mzxw8dIcit1HzviY+YnSLPX9tFymEiRdC1SGCEbtE!n YFf3799zifNQaSsCTg/vmYFAsNHgHnbVCdrIFihJjk+5qgvwmQCMuWr7qqF0luFKESrwO WE2Rsv!4oqHftBazT+nh19YbHxXUg==
X-Complaints-To: abuse (AT) dsl (DOT) pipex.net
X-DMCA-Complaints-To: abuse (AT) dsl (DOT) pipex.net
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.39
Bytes: 2610
Xref: number1.nntp.dca.giganews.com comp.databases.theory:68083

Hi all,
I have 2 tables, "sims" (as in mobile phone sim cards) and "phones" (as
in mobile phones). I can add any number of sim cards to the "sims"
table and any number of mobile phones to the "phones" table. Simple enough.

Rule 1: A sim card can either be in a phone, or not in a phone. It
cannot be in more than one phone.

Rule 2: A phone can either have one sim inserted, or no sim inserted.

So the relationship between the phone and sim is 0:1 to 0:1, I think..

There's several ways I could implement this, but the two most obvious to
me so far are:

### Method 1

SIMS table:
sim_id

PHONES table:
phone_id
phone_sim_id references sims(sim_id)


### Method 2

PHONES table:
phone_id

SIMS table:
sim_id
sim_phone_id references phones(phone_id)

So problem number 1 is, which way round makes more sense? My first
instinct was method 1. It seemed to make sense to say "the phone has
this sim card", though I suppose you could just as easily turn that on
its head.

Problem number 2 is, using either method above can break the rules and
create an impossible situation. For example, several phones could
reference the same sim card in method 1, and several sim cards could
reference the same phone in method 2. Would the proper way to ensure
integrity in this case be to add a "unique" modifier to the reference
field? e.g:

phone_sim_id references sims(sim_id) unique

Any advice on the above would be much appreciated.

Thanks,

Mark.

Reply With Quote
  #2  
Old   
Bob Badour
 
Posts: n/a

Default Re: Simple database design question - 09-30-2008 , 11:23 AM






Mark S. (UK) wrote:

Quote:
Hi all,
I have 2 tables, "sims" (as in mobile phone sim cards) and "phones" (as
in mobile phones). I can add any number of sim cards to the "sims"
table and any number of mobile phones to the "phones" table. Simple enough.

Rule 1: A sim card can either be in a phone, or not in a phone. It
cannot be in more than one phone.

Rule 2: A phone can either have one sim inserted, or no sim inserted.

So the relationship between the phone and sim is 0:1 to 0:1, I think..

There's several ways I could implement this, but the two most obvious to
me so far are:

### Method 1

SIMS table:
sim_id

PHONES table:
phone_id
phone_sim_id references sims(sim_id)


### Method 2

PHONES table:
phone_id

SIMS table:
sim_id
sim_phone_id references phones(phone_id)

So problem number 1 is, which way round makes more sense? My first
instinct was method 1. It seemed to make sense to say "the phone has
this sim card", though I suppose you could just as easily turn that on
its head.
Neither of the above handle both 0 cases.


Quote:
Problem number 2 is, using either method above can break the rules and
create an impossible situation. For example, several phones could
reference the same sim card in method 1, and several sim cards could
reference the same phone in method 2. Would the proper way to ensure
integrity in this case be to add a "unique" modifier to the reference
field? e.g:

phone_sim_id references sims(sim_id) unique

Any advice on the above would be much appreciated.
If one thinks about the relations above as predicates instead of as
tables, one naturally creates a much better design than either of the above.


Reply With Quote
  #3  
Old   
Bob Badour
 
Posts: n/a

Default Re: Simple database design question - 09-30-2008 , 11:23 AM



Mark S. (UK) wrote:

Quote:
Hi all,
I have 2 tables, "sims" (as in mobile phone sim cards) and "phones" (as
in mobile phones). I can add any number of sim cards to the "sims"
table and any number of mobile phones to the "phones" table. Simple enough.

Rule 1: A sim card can either be in a phone, or not in a phone. It
cannot be in more than one phone.

Rule 2: A phone can either have one sim inserted, or no sim inserted.

So the relationship between the phone and sim is 0:1 to 0:1, I think..

There's several ways I could implement this, but the two most obvious to
me so far are:

### Method 1

SIMS table:
sim_id

PHONES table:
phone_id
phone_sim_id references sims(sim_id)


### Method 2

PHONES table:
phone_id

SIMS table:
sim_id
sim_phone_id references phones(phone_id)

So problem number 1 is, which way round makes more sense? My first
instinct was method 1. It seemed to make sense to say "the phone has
this sim card", though I suppose you could just as easily turn that on
its head.
Neither of the above handle both 0 cases.


Quote:
Problem number 2 is, using either method above can break the rules and
create an impossible situation. For example, several phones could
reference the same sim card in method 1, and several sim cards could
reference the same phone in method 2. Would the proper way to ensure
integrity in this case be to add a "unique" modifier to the reference
field? e.g:

phone_sim_id references sims(sim_id) unique

Any advice on the above would be much appreciated.
If one thinks about the relations above as predicates instead of as
tables, one naturally creates a much better design than either of the above.


Reply With Quote
  #4  
Old   
Bob Badour
 
Posts: n/a

Default Re: Simple database design question - 09-30-2008 , 11:23 AM



Mark S. (UK) wrote:

Quote:
Hi all,
I have 2 tables, "sims" (as in mobile phone sim cards) and "phones" (as
in mobile phones). I can add any number of sim cards to the "sims"
table and any number of mobile phones to the "phones" table. Simple enough.

Rule 1: A sim card can either be in a phone, or not in a phone. It
cannot be in more than one phone.

Rule 2: A phone can either have one sim inserted, or no sim inserted.

So the relationship between the phone and sim is 0:1 to 0:1, I think..

There's several ways I could implement this, but the two most obvious to
me so far are:

### Method 1

SIMS table:
sim_id

PHONES table:
phone_id
phone_sim_id references sims(sim_id)


### Method 2

PHONES table:
phone_id

SIMS table:
sim_id
sim_phone_id references phones(phone_id)

So problem number 1 is, which way round makes more sense? My first
instinct was method 1. It seemed to make sense to say "the phone has
this sim card", though I suppose you could just as easily turn that on
its head.
Neither of the above handle both 0 cases.


Quote:
Problem number 2 is, using either method above can break the rules and
create an impossible situation. For example, several phones could
reference the same sim card in method 1, and several sim cards could
reference the same phone in method 2. Would the proper way to ensure
integrity in this case be to add a "unique" modifier to the reference
field? e.g:

phone_sim_id references sims(sim_id) unique

Any advice on the above would be much appreciated.
If one thinks about the relations above as predicates instead of as
tables, one naturally creates a much better design than either of the above.


Reply With Quote
  #5  
Old   
Bob Badour
 
Posts: n/a

Default Re: Simple database design question - 09-30-2008 , 11:23 AM



Mark S. (UK) wrote:

Quote:
Hi all,
I have 2 tables, "sims" (as in mobile phone sim cards) and "phones" (as
in mobile phones). I can add any number of sim cards to the "sims"
table and any number of mobile phones to the "phones" table. Simple enough.

Rule 1: A sim card can either be in a phone, or not in a phone. It
cannot be in more than one phone.

Rule 2: A phone can either have one sim inserted, or no sim inserted.

So the relationship between the phone and sim is 0:1 to 0:1, I think..

There's several ways I could implement this, but the two most obvious to
me so far are:

### Method 1

SIMS table:
sim_id

PHONES table:
phone_id
phone_sim_id references sims(sim_id)


### Method 2

PHONES table:
phone_id

SIMS table:
sim_id
sim_phone_id references phones(phone_id)

So problem number 1 is, which way round makes more sense? My first
instinct was method 1. It seemed to make sense to say "the phone has
this sim card", though I suppose you could just as easily turn that on
its head.
Neither of the above handle both 0 cases.


Quote:
Problem number 2 is, using either method above can break the rules and
create an impossible situation. For example, several phones could
reference the same sim card in method 1, and several sim cards could
reference the same phone in method 2. Would the proper way to ensure
integrity in this case be to add a "unique" modifier to the reference
field? e.g:

phone_sim_id references sims(sim_id) unique

Any advice on the above would be much appreciated.
If one thinks about the relations above as predicates instead of as
tables, one naturally creates a much better design than either of the above.


Reply With Quote
  #6  
Old   
Bob Badour
 
Posts: n/a

Default Re: Simple database design question - 09-30-2008 , 11:23 AM



Mark S. (UK) wrote:

Quote:
Hi all,
I have 2 tables, "sims" (as in mobile phone sim cards) and "phones" (as
in mobile phones). I can add any number of sim cards to the "sims"
table and any number of mobile phones to the "phones" table. Simple enough.

Rule 1: A sim card can either be in a phone, or not in a phone. It
cannot be in more than one phone.

Rule 2: A phone can either have one sim inserted, or no sim inserted.

So the relationship between the phone and sim is 0:1 to 0:1, I think..

There's several ways I could implement this, but the two most obvious to
me so far are:

### Method 1

SIMS table:
sim_id

PHONES table:
phone_id
phone_sim_id references sims(sim_id)


### Method 2

PHONES table:
phone_id

SIMS table:
sim_id
sim_phone_id references phones(phone_id)

So problem number 1 is, which way round makes more sense? My first
instinct was method 1. It seemed to make sense to say "the phone has
this sim card", though I suppose you could just as easily turn that on
its head.
Neither of the above handle both 0 cases.


Quote:
Problem number 2 is, using either method above can break the rules and
create an impossible situation. For example, several phones could
reference the same sim card in method 1, and several sim cards could
reference the same phone in method 2. Would the proper way to ensure
integrity in this case be to add a "unique" modifier to the reference
field? e.g:

phone_sim_id references sims(sim_id) unique

Any advice on the above would be much appreciated.
If one thinks about the relations above as predicates instead of as
tables, one naturally creates a much better design than either of the above.


Reply With Quote
  #7  
Old   
Bob Badour
 
Posts: n/a

Default Re: Simple database design question - 09-30-2008 , 11:23 AM



Mark S. (UK) wrote:

Quote:
Hi all,
I have 2 tables, "sims" (as in mobile phone sim cards) and "phones" (as
in mobile phones). I can add any number of sim cards to the "sims"
table and any number of mobile phones to the "phones" table. Simple enough.

Rule 1: A sim card can either be in a phone, or not in a phone. It
cannot be in more than one phone.

Rule 2: A phone can either have one sim inserted, or no sim inserted.

So the relationship between the phone and sim is 0:1 to 0:1, I think..

There's several ways I could implement this, but the two most obvious to
me so far are:

### Method 1

SIMS table:
sim_id

PHONES table:
phone_id
phone_sim_id references sims(sim_id)


### Method 2

PHONES table:
phone_id

SIMS table:
sim_id
sim_phone_id references phones(phone_id)

So problem number 1 is, which way round makes more sense? My first
instinct was method 1. It seemed to make sense to say "the phone has
this sim card", though I suppose you could just as easily turn that on
its head.
Neither of the above handle both 0 cases.


Quote:
Problem number 2 is, using either method above can break the rules and
create an impossible situation. For example, several phones could
reference the same sim card in method 1, and several sim cards could
reference the same phone in method 2. Would the proper way to ensure
integrity in this case be to add a "unique" modifier to the reference
field? e.g:

phone_sim_id references sims(sim_id) unique

Any advice on the above would be much appreciated.
If one thinks about the relations above as predicates instead of as
tables, one naturally creates a much better design than either of the above.


Reply With Quote
  #8  
Old   
Bob Badour
 
Posts: n/a

Default Re: Simple database design question - 09-30-2008 , 11:23 AM



Mark S. (UK) wrote:

Quote:
Hi all,
I have 2 tables, "sims" (as in mobile phone sim cards) and "phones" (as
in mobile phones). I can add any number of sim cards to the "sims"
table and any number of mobile phones to the "phones" table. Simple enough.

Rule 1: A sim card can either be in a phone, or not in a phone. It
cannot be in more than one phone.

Rule 2: A phone can either have one sim inserted, or no sim inserted.

So the relationship between the phone and sim is 0:1 to 0:1, I think..

There's several ways I could implement this, but the two most obvious to
me so far are:

### Method 1

SIMS table:
sim_id

PHONES table:
phone_id
phone_sim_id references sims(sim_id)


### Method 2

PHONES table:
phone_id

SIMS table:
sim_id
sim_phone_id references phones(phone_id)

So problem number 1 is, which way round makes more sense? My first
instinct was method 1. It seemed to make sense to say "the phone has
this sim card", though I suppose you could just as easily turn that on
its head.
Neither of the above handle both 0 cases.


Quote:
Problem number 2 is, using either method above can break the rules and
create an impossible situation. For example, several phones could
reference the same sim card in method 1, and several sim cards could
reference the same phone in method 2. Would the proper way to ensure
integrity in this case be to add a "unique" modifier to the reference
field? e.g:

phone_sim_id references sims(sim_id) unique

Any advice on the above would be much appreciated.
If one thinks about the relations above as predicates instead of as
tables, one naturally creates a much better design than either of the above.


Reply With Quote
  #9  
Old   
Mark S. (UK)
 
Posts: n/a

Default Re: Simple database design question - 09-30-2008 , 02:24 PM



Bob Badour wrote:
Quote:
Mark S. (UK) wrote:

Hi all,
I have 2 tables, "sims" (as in mobile phone sim cards) and "phones" (as
in mobile phones). I can add any number of sim cards to the "sims"
table and any number of mobile phones to the "phones" table. Simple
enough.

Rule 1: A sim card can either be in a phone, or not in a phone. It
cannot be in more than one phone.

Rule 2: A phone can either have one sim inserted, or no sim inserted.

So the relationship between the phone and sim is 0:1 to 0:1, I think..

There's several ways I could implement this, but the two most obvious to
me so far are:

### Method 1

SIMS table:
sim_id

PHONES table:
phone_id
phone_sim_id references sims(sim_id)


### Method 2

PHONES table:
phone_id

SIMS table:
sim_id
sim_phone_id references phones(phone_id)

So problem number 1 is, which way round makes more sense? My first
instinct was method 1. It seemed to make sense to say "the phone has
this sim card", though I suppose you could just as easily turn that on
its head.

Neither of the above handle both 0 cases.
In method 1, if phone_sim_id is NULL, then is it not related to 0
records? Or am I missing something?

Quote:
Problem number 2 is, using either method above can break the rules and
create an impossible situation. For example, several phones could
reference the same sim card in method 1, and several sim cards could
reference the same phone in method 2. Would the proper way to ensure
integrity in this case be to add a "unique" modifier to the reference
field? e.g:

phone_sim_id references sims(sim_id) unique

Any advice on the above would be much appreciated.

If one thinks about the relations above as predicates instead of as
tables, one naturally creates a much better design than either of the
above.
So the predicate would be "phone xxxxx uses sim xxxxx"..

Could you elaborate a little more or maybe direct me at some text that
might help? Or another hint? I would like to figure it out for myself
if I can, but I think I'm mentally stuck in one way of thinking here; I
can only think of relating the two items of data either as I've
described above or using a dedicated relation table.. or possibly an index.

How about:

PHONE:
phone_id

SIM:
sim_id

RELATION:
phone_id
sim_id

unique index on phone_id, sim_id ...

Am I at least on the right lines?

Thanks,

Mark.
--


Reply With Quote
  #10  
Old   
Mark S. (UK)
 
Posts: n/a

Default Re: Simple database design question - 09-30-2008 , 02:24 PM



Bob Badour wrote:
Quote:
Mark S. (UK) wrote:

Hi all,
I have 2 tables, "sims" (as in mobile phone sim cards) and "phones" (as
in mobile phones). I can add any number of sim cards to the "sims"
table and any number of mobile phones to the "phones" table. Simple
enough.

Rule 1: A sim card can either be in a phone, or not in a phone. It
cannot be in more than one phone.

Rule 2: A phone can either have one sim inserted, or no sim inserted.

So the relationship between the phone and sim is 0:1 to 0:1, I think..

There's several ways I could implement this, but the two most obvious to
me so far are:

### Method 1

SIMS table:
sim_id

PHONES table:
phone_id
phone_sim_id references sims(sim_id)


### Method 2

PHONES table:
phone_id

SIMS table:
sim_id
sim_phone_id references phones(phone_id)

So problem number 1 is, which way round makes more sense? My first
instinct was method 1. It seemed to make sense to say "the phone has
this sim card", though I suppose you could just as easily turn that on
its head.

Neither of the above handle both 0 cases.
In method 1, if phone_sim_id is NULL, then is it not related to 0
records? Or am I missing something?

Quote:
Problem number 2 is, using either method above can break the rules and
create an impossible situation. For example, several phones could
reference the same sim card in method 1, and several sim cards could
reference the same phone in method 2. Would the proper way to ensure
integrity in this case be to add a "unique" modifier to the reference
field? e.g:

phone_sim_id references sims(sim_id) unique

Any advice on the above would be much appreciated.

If one thinks about the relations above as predicates instead of as
tables, one naturally creates a much better design than either of the
above.
So the predicate would be "phone xxxxx uses sim xxxxx"..

Could you elaborate a little more or maybe direct me at some text that
might help? Or another hint? I would like to figure it out for myself
if I can, but I think I'm mentally stuck in one way of thinking here; I
can only think of relating the two items of data either as I've
described above or using a dedicated relation table.. or possibly an index.

How about:

PHONE:
phone_id

SIM:
sim_id

RELATION:
phone_id
sim_id

unique index on phone_id, sim_id ...

Am I at least on the right lines?

Thanks,

Mark.
--


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.