![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
#4
| |||
| |||
|
|
I'm in the middle of something a bit tedious and not very database related so to relieve the boredom I thought I'd stir it up a bit here. |
|
I have to confess that I don't see why you'd ever want a "key" that isn't a key. I can see why you'd want to port a database and data with such existing keys from product X to Ingres. What I can't see is what sort of real-world concept is modelled by doing that. Am I not being imaginative enough? The only possible reason I've come up with is the case where two or more fact types are conflated in the same table, but that's no reason at all. Am I being thick? Or is a non-unique key the logical blunder I think it is? |
#5
| |||
| |||
|
|
On 17/08/2011 10:39, Roy Hann wrote: I'm in the middle of something a bit tedious and not very database related so to relieve the boredom I thought I'd stir it up a bit here. snip I have to confess that I don't see why you'd ever want a "key" that isn't a key. I can see why you'd want to port a database and data with such existing keys from product X to Ingres. What I can't see is what sort of real-world concept is modelled by doing that. Am I not being imaginative enough? The only possible reason I've come up with is the case where two or more fact types are conflated in the same table, but that's no reason at all. Am I being thick? Or is a non-unique key the logical blunder I think it is? I can see a case for a unique key with null, but not based on a single column. I might be barking up the wrong tree altogether. |
|
Lets say you wanted a unique id for somebody - fred bloggs. In an ideal world you would also have a social security number, passport number, driving licence, blockbuster membership number, library card number - you get the idea. Many Fred Bloggs, but the others are unique. In practice, you might have only some of these fields, but whatever the combination of missing fields you should be able to establish a unique key even with values missing(null). So lets say that for ID purposes I have a primary key based upon SS Number, Passport Number, Driving Licence Number. I might have a unique key for each of these fields, yet it may contain null entries. So to identify my person, I want any or all of these fields to be present, and if they are present the value must be unique in the given column and therefore the value for the primary key is also unique too because I need my primary key to have one of these three columns with a non-null value. It seems to me to be good because it allows keys to be incomplete yet unique. Do I have this all wrong? |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
Think of DBMS that consider an empty string as a NULL value. |
|
Then a key like (first_name, middle_name, last_name) would end up in values containing NULL values (as I don't have a middle name). |
#8
| ||||
| ||||
|
|
On 17/08/2011 10:39, Roy Hann wrote: I'm in the middle of something a bit tedious and not very database related so to relieve the boredom I thought I'd stir it up a bit here. snip I have to confess that I don't see why you'd ever want a "key" that isn't a key. I can see why you'd want to port a database and data with such existing keys from product X to Ingres. What I can't see is what sort of real-world concept is modelled by doing that. Am I not being imaginative enough? The only possible reason I've come up with is the case where two or more fact types are conflated in the same table, but that's no reason at all. Am I being thick? Or is a non-unique key the logical blunder I think it is? I can see a case for a unique key with null, but not based on a single column. I might be barking up the wrong tree altogether. Lets say you wanted a unique id for somebody - fred bloggs. In an ideal world you would also have a social security number, passport number, driving licence, blockbuster membership number, library card number - you get the idea. Many Fred Bloggs, but the others are unique. In practice, you might have only some of these fields, but whatever the combination of missing fields you should be able to establish a unique key even with values missing(null). |
|
So lets say that for ID purposes I have a primary key based upon SS Number, Passport Number, Driving Licence Number. |
|
I might have a unique key for each of these fields, yet it may contain null entries. So to identify my person, I want any or all of these fields to be present, |
|
and if they are present the value must be unique in the given column and therefore the value for the primary key is also unique too because I need my primary key to have one of these three columns with a non-null value. It seems to me to be good because it allows keys to be incomplete yet unique. Do I have this all wrong? |
#9
| |||
| |||
|
|
I can see a case for a unique key with null, but not based on a single column. I might be barking up the wrong tree altogether. That should have been more like I can see a case for a unique key with null, but not a primary key based on a single column with null, but a primary key with nullable columns is fine (provided one column is not null and is unique). |
#10
| |||
| |||
|
|
I'd argue that allowing nullable fields in unique constraints was approaching a contradiction in terms. But I could see that in the case of a multicolumn constraint demanding that all the columns must be non nullable may be overkill. |
![]() |
| Thread Tools | |
| Display Modes | |
| |