3 ms·
> IMO most data in DBs has a natural key. Why add a fake key? In our application users generate declarations. On the declarations users need to enter invoice n
by magicalhippo 8y ago
> IMO most data in DBs has a natural key. Why add a fake key?
In our application users generate declarations. On the declarations users need to enter invoice numbers (with amount and date). So a natural key would be a compound key consisting of declaration id and invoice number (which has to be unique per declaration anyway).
Declarations also contain goods items, and they need to be linked to an invoice. No problem there, just make a foreign key pointing to the invoice on the declaration.
However, users sometime type the wrong thing. They finish up a declaration and while double checking notice that they typed the wrong invoice number. So they want to change the invoice number. With the natural key you then need to update all the goods items linked to it as well.
Much easier to just have a "fake" key (autoinc or otherwise) and use that to link the goods items and invoices.
Similar issues crop up all over our application, so unless there's a really good reason we avoid natural keys.
That said, we don't have a single UUID key. We do not have fully disconnected clients, so we use sequence generators for "non-leaf" keys such as declaration id's.
- tempguy9999 8y agoThanks for a fine example of the discrepancy between my world (the data being canonical, normalised and all-round platonically ideal) and the real world ("but I never meant to do thaaaaat!"). Yup, point taken.