Answer the question
In order to leave comments, you need to log in
Is using a string primary key justified?
For example, there is a table that stores a catalog of cars. Is it justified to make the state number the primary key, i.e. , let's say an nchar(6) field? And if not, in what cases is it justified? Here, after all, we get rid of the int field with auto-increment, and there is no need to do additional checks for the uniqueness of the number.
How will using a string pk affect performance?
Answer the question
In order to leave comments, you need to log in
Is it justified to make the state number the primary key, i.e. , let's say an nchar(6) field?
1. No good. The key must be a number, this time. This affects performance.
2. The assumption about the uniqueness of car numbers is gloom. It is quite possible that two cars with the same number will appear, just one of them was deregistered 100,500 years ago.
wrong. car number is not unique.
in 2013 I went to the traffic police, paid 2000 rubles and put my old state number on a new car
If the string key is not too wide, then it is much better than using a "fake" PK. It does NOT affect the performance of inserts / joins within the real error: you don’t need to listen to those who once read this bike, it’s enough to put up a simple experiment yourself with a real average record width. The only limitation here is the possible reuse of the key, but if this is not allowed, as in this problem, then it should be done.
For example, there is a table that stores a catalog of cars. Is it justified to make the state number the primary keyJustified, but Mr. the number does not define the entity (car). Possibly determines the VIN, but this must be determined by the subject area. Using a surrogate key (usually an auto-incrementing number, although it can be anything, for example, uniqueidentifier 0E984725-C51C-4BF4-9960-E1C80E27ABA0) eliminates the need to look up (and understand its uniqueness) a natural key.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question