News for hackers. Stuff that matters.
Re:What does First Normal Form mean? by turbocon on Friday June 18, 2021 @11:46AM (#27551570)
It's rare in practice but occasionally rows have natural unique identifiers that are useable.

The textbook case would be student IDs in a university database where each row corresponds to a single student. However some universities view the student id as sensitive information (kind of like a ssn in the US) and so in that scenario it should be aliased to some other key to prevent the student id from being present in multiple tables as a foreign key.

Re:What does First Normal Form mean? by bart_spoon on Friday June 18, 2021 @07:32PM (#27556222)
I think a natural key that I’ve encountered is a database containing professional NBA data. Teams never play more than once per day, and there are only two teams in the game, so a natural (composite) key for games is simply the date of the game and the two teams that played. You can create a “game ID” if you wish, but you aren’t actually doing anything but adding a column of redundant information.
Re:What does First Normal Form mean? by jameshart on Friday June 18, 2021 @12:38PM (#27552176)
Student IDs are certainly not ‘natural’ keys.

I am almost entirely convinced that there is actually no such thing as a natural key.

Re:What does First Normal Form mean? by wolfgang42 on Friday June 18, 2021 @02:45PM (#27553522)
a "natural key" is frequently just a really foreign key in a database you and your org don't manage. — 'wweston, https://news.ycombinator.com/item?id=27349246
Re:What does First Normal Form mean? by mulmen on Friday June 18, 2021 @02:31PM (#27553374)
Natural keys are everywhere. They are just less interesting than the relationships. My name is a natural key. It uniquely identifies my name. The wheels come off if you expect it to uniquely identify me. But with natural keys that's never actually necessary.

When I buy a car they record my name, my date of birth, the time of the sale and some details about the car, such as the VIN, which is its name. That provides enough information to form a natural key to identify the sale.

At no point does a database actually have a concept of who I am really, only the relevant data points to satisfy its own relational model.

Any database that means to track information about people would be able to construct a natural key from my name, my mothers name and some information about my birth, such as the doctor, hospital and time.

Re:What does First Normal Form mean? by jameshart on Saturday June 19, 2021 @11:18AM (#27561224)
(Interesting cultural assumption there that people are born in hospitals under the supervision of doctors)

The thing is to qualify as a natural key I think it has to be precisely recoverable just from first principles wherever you encounter the artifact it references. The birth details aren’t inherent to the person, they’re datapoints about them.

All the identifiers you propose to make up mnatural’ keys are synthetic keys from some other authority for identifying things. VINs obviously are synthetic identifiers, but so are names, dates, hospital addresses.

As you rightly say, a string is a natural key for itself; likewise a number.

The only other ‘natural key’ I can think of is atomic number for identifying chemical elements.

Re:What does First Normal Form mean? by mulmen on Saturday June 19, 2021 @03:24PM (#27563591)
I said a database that tracks people could identify me using information about my birth. Not that everyone is born in a hospital or by a doctor.

By your definition there are no natural keys. But since that definition isn't useful we instead use one that is. The natural key is the identifier by which the thing is already known.

https://en.wikipedia.org/wiki/Natural_key

Re:What does First Normal Form mean? by CRConrad on Monday June 28, 2021 @07:41AM (#27660550)
> I said a database that tracks people could identify me using information about my birth.

And your name, you said.

> The natural key is the identifier by which the thing is already known.

And then you change your name.

Re:What does First Normal Form mean? by denton-scratch on Saturday June 19, 2021 @11:55PM (#27566947)
Probably not unique, though. Well, yours might be; but in general, a person's name isn't a reliable unique identifier. Nor anyone's name. Even if you have a timestramp, you can't be sure it's unique.
Re:What does First Normal Form mean? by dragonwriter on Friday June 18, 2021 @06:50PM (#27555875)
Dates are natural keys in a calendar table. The composite of the foreign key values is a natural key in a join table expressing a unique relationship between entities in two or more other tables, perhaps with additional attributes, even if those values are surrogate keys in their own tables.
Re:What does First Normal Form mean? by jameshart on Saturday June 19, 2021 @11:08AM (#27561098)
Dates aren’t natural. I know of at least three different date keys in different calendars that refer to the same calendar day - choosing to use one particular date standard to refer to days is choosing a pre-existing synthetic key, not a ‘natural’ one.
Re:What does First Normal Form mean? by dragonwriter on Sunday June 20, 2021 @10:51AM (#27570578)
> I know of at least three different date keys in different calendars that refer to the same calendar day

Aside from the fact that you have very limited knowledge of calebdar systems, I’m not sure what this is supposed to prove. “Natural” in “natural key” doesn't mean “exists in nature outside of human invention”, it means “exists outside the database as part of the data in the data model, rather than being created solely to have a ubique key in the database ubder design".

The date in whatever particular calendar system is used in the data model is a natural key for a calendar table.

Re:What does First Normal Form mean? by mulmen on Saturday June 19, 2021 @03:42PM (#27563745)
Dates are natural keys.

You seem to be conflating format and value. 1,234,567 and 1234567 are the same number. 19-Jun-21 and 2021-06-19 are the same date. Databases already handle this.

Re:What does First Normal Form mean? by jameshart on Saturday June 19, 2021 @04:36PM (#27564243)
19 June 2021 is also known as:

Dhuʻl-Qiʻdah 9, 1442 AH

9 Tamuz 5781

Re:What does First Normal Form mean? by mulmen on Saturday June 19, 2021 @04:41PM (#27564284)
Great! Then if they are unambiguous they can be inserted directly or disambiguated and then inserted. At query time any format can be used to represent them to a user.
Re:What does First Normal Form mean? by jameshart on Saturday June 19, 2021 @04:54PM (#27564382)
Ah, so you're suggesting instead of storing 'what a person calls this date' as the key, you instead convert it to some underlying representation that you can then choose to present in different calendars - like a UNIX epoch-relative offset or something.

Congratulations, you just created another synthetic key for describing dates.

Re:What does First Normal Form mean? by goto11 on Monday June 21, 2021 @03:51AM (#27577164)
That is not what synthetic key means. A synthetic key is a key which does not carry any information, like an auto-incremented integer. A date is a natural key, regardless of the underlying representation.
Re:What does First Normal Form mean? by mulmen on Saturday June 19, 2021 @05:24PM (#27564586)
The date is a natural key. The format string is only a representation. Implementation details are irrelevant to the definition of a natural key.
Re:What does First Normal Form mean? by CharlesW on Friday June 18, 2021 @02:35PM (#27553413)
> I am almost entirely convinced that there is actually no such thing as a natural key.

Yes! Or if it is now, there's a future scenario where that will have proven to have been a poor decision.

Re:What does First Normal Form mean? by dragonwriter on Friday June 18, 2021 @06:54PM (#27555898)
> The textbook case would be student IDs in a university database where each row corresponds to a single student

“Student IDs” are an example of surrogate keys, though they may be surrogate keys in a system predating and outside of the DB.

(And if the mapping between them and actual students are managed by an error-prone process outside of the DB, they probably aren’t good primary keys for a table of students.)

Re:What does First Normal Form mean? by TeMPOraL on Friday June 18, 2021 @11:49AM (#27551615)
> However some universities view the student id as sensitive information (kind of like a ssn in the US) and so in that scenario it should be aliased to some other key to prevent the student id from being present in multiple tables as a foreign key.

It is ironic, given that the whole reason to have a student ID is for it to be a primary key in some database somewhere.

Re:What does First Normal Form mean? by whatshisface on Friday June 18, 2021 @12:31PM (#27552088)
Databases are vulnerable to a particular type of folkloric magic:

https://en.m.wikipedia.org/wiki/True_name

Re:What does First Normal Form mean? by wombatpm on Friday June 18, 2021 @05:33PM (#27555273)
In the 1980's your student ID was most likely your SSN