![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
If a specific case makes a response easier, mine is registration on a web site. There is a natural key because the user name for registration must be unique. However, the user name is likely to change fairly frequently and I really don't want to change the foreign key on many records after every change of name. Please don't answer on the basis that surrogate keys are "bad". I'm sure you can think of a case when a generated primary key is required and you have some thoughts on how that should accomplished. |
#3
| ||||
| ||||
|
|
In a separate thread I was chastised for using the database to generate primary keys. CELKO insisted "we invent a key with check digits, validation rules and an audit trail within our enterprise". I might have ignored the advice from someone else but CELKO's posts have been consistently helpful and erudite. |
|
I remember generating dozens of pages of "computer paper" containing customer numbers replete with the latest fashion in check digits so that the clerical staff could assign a number to a new customer and code the incoming orders with their assigned number. I have assumed that, these days, primary keys are either an intrinsic part of the data or are computer generated and that, in either case, the user is almost never obliged to know what they are. |
|
If a specific case makes a response easier, mine is registration on a web site. There is a natural key because the user name for registration must be unique. However, the user name is likely to change fairly frequently and I really don't want to change the foreign key on many records after every change of name. |
|
Please don't answer on the basis that surrogate keys are "bad". I'm sure you can think of a case when a generated primary key is required and you have some thoughts on how that should accomplished. |
#4
| |||
| |||
|
|
David Segall wrote: If a specific case makes a response easier, mine is registration on a web site. There is a natural key because the user name for registration must be unique. However, the user name is likely to change fairly frequently and I really don't want to change the foreign key on many records after every change of name. Please don't answer on the basis that surrogate keys are "bad". I'm sure you can think of a case when a generated primary key is required and you have some thoughts on how that should accomplished. Maybe I am being dumb but I do not understand your question. What is wrong with using IDENTITY or SEQUENCE? That _is_ my question and I should have said so more clearly. |
#5
| |||
| |||
|
|
Please don't answer on the basis that surrogate keys are "bad". I'm sure you can think of a case when a generated primary key is required and you have some thoughts on how that should accomplished. |
#6
| |||
| |||
|
|
Robert Klemme <shortcutter (AT) googlemail (DOT) com> wrote: Maybe I am being dumb but I do not understand your question. What is wrong with using IDENTITY or SEQUENCE? That _is_ my question and I should have said so more clearly. I asked in a separate thread "Is there a database independent way of obtaining the generated key after the insertion?" and received the scathing response from CELKO "... newbies prefer to do it wrong by using auto-increments or other proprietary stuff that cannot be verified or validated BECAUSE it is easier than real RDBMS design. They want to have a magical, universal "one-size-fits-all" answer that does not require you ACTUALLY understand the problem domain" I assumed, because of the respondent, that he had a valid point and that there was a better, generally accepted, way of generating primary keys. |
#7
| |||
| |||
|
|
Maybe I am being dumb but I do not understand your question. What is wrong with using IDENTITY or SEQUENCE? That _is_ my question and I should have said so more clearly. I asked in a separate thread "Is there a database independent way of obtaining the generated key after the insertion?" and received the scathing response from CELKO "... newbies prefer to do it wrong by using auto-increments or other proprietary stuff that cannot be verified or validated BECAUSE it is easier than real RDBMS design. They want to have a magical, universal "one-size-fits-all" answer that does not require you ACTUALLY understand the problem domain" |
#8
| |||||||
| |||||||
|
|
"David Segall" <david (AT) address (DOT) invalid> wrote in message news:nhmik2dqruobck1dvv8ld6cjs2mmr6t7o9 (AT) 4ax (DOT) com... Maybe I am being dumb but I do not understand your question. What is wrong with using IDENTITY or SEQUENCE? That _is_ my question and I should have said so more clearly. I asked in a separate thread "Is there a database independent way of obtaining the generated key after the insertion?" and received the scathing response from CELKO "... newbies prefer to do it wrong by using auto-increments or other proprietary stuff that cannot be verified or validated BECAUSE it is easier than real RDBMS design. They want to have a magical, universal "one-size-fits-all" answer that does not require you ACTUALLY understand the problem domain" Ignore the other person. |
|
To avoid complications in any relational database, the primary key cannot have any meaning within the system for the majority of your data. |
|
If it does, then sooner or later people want to change the value and primary key values should not be changeable for any reason. |
|
The concept of sequences were invented because the overhead of getting the next sequence from a database table resulted in needing the transaction to be committed before the next person could get the next sequence. This severely reduces the scalability of the database. Sequences therefore obtain their value outside of the transaction. In general, people either have an auto incrementing number as a primary key if uniqueness is required within a single database, or make use of global identifiers (GUID) to generate primary keys. |
|
These use algorithms to guarantee that keys generated will be unique by machine by time. However, they are significantly larger fields and beause the values generated are algorthm-based, you cannot identify sequence as you would with an incrementing number. |
|
Now what I describe above should always be used for 'transactional' data such as creating an order or adding an employee to the system. |
|
However, for basic 'referential' data (and I mean basic as the term referential is relative, so we're talking about code tables for the most part here), you may wish to have this generated sequence to be an alternative key and use the unique 'code' field as the primary key. You have to be absolutely sure that the 'code' field will not change though, but for the most part, many like to use the 'code' field because it assists when doing lookups. In these cases, storing a generated number in the table performing the lookup to the 'code' table is meaningless, and having significance in the primary key can be advantageous. AMO |
#9
| |||||||
| |||||||
|
|
No, take Joe's advice in context. |
|
WRONG! The first assumption is that the PK indentifies the entity being modelled. A PK that has no meaning makes no sense in a Relational Model. You are just proposing using a relational model database as a network model one when you suggest this. Please go back and read Codd. |
|
While the facts you say in that sentence are true, that is not a reason to go to surrogates for a PK. In practical real world systems, you must manage changes to the PK. Within the DB that might be as simple as deleting the old row and inserting a new one, or as complex as cascading copies of data from the old PK to the new PK. In the later case, you might consider surrogates to reduce such work, but only as a last choice, not a primary choice. |
|
The concept of sequences were invented because the overhead of getting the next sequence from a database table resulted in needing the transaction to be committed before the next person could get the next sequence. This severely reduces the scalability of the database. Sequences therefore obtain their value outside of the transaction. In general, people either have an auto incrementing number as a primary key if uniqueness is required within a single database, or make use of global identifiers (GUID) to generate primary keys. You mean people People that do not understand good Relational design. |
|
If the goal is to creat a Unique ID, you should not care about the order. That just shows again, AMO, that you are not thinking correctly about this issue. |
|
Okay, let's see what you consider non-'transactional' data ... |
|
And to rephrase your last remark, I would say: having significance in the primary key IS the advantage. and that's why pseudokeys should be used with caution. Ed |
#10
| |||
| |||
|
|
I think that anyone taking Codd's advice and not deviating from that to cater for real world requirements will find that they are going down a path where relational thinking is fixed in the past. Codd's relational rules have not changed over time meaning that those that follow his rules work on the assumption that they are correct and definitive even with ever changing database engines and their extensions over time. |
![]() |
| Thread Tools | |
| Display Modes | |
| |