This is a very controversial issue, with a lot of emotions on both sides.
In my humble opinion, if there is a good, affordable natural key - like ISBN - I use it. Anyway, I'm going to store it in a database. Yes, the natural key is usually larger than the integer auto-increment key, but I think this problem is bloated. Today, disk space is cheap. I would be more worried about this, and it took more time. If you were talking about an 80-byte text field as the primary key, I would say no. But if you are thinking of using a 10-byte ISBN instead of an 8-byte big integer, I cannot imagine that this brings most of the performance.
Sometimes there is a performance advantage for natural keys. Suppose, for example, that I want to find how many copies of this book have been sold. I don’t care about any information from the main record of the book. If the primary key is ISBN, I can simply write "select count (*) from the sale, where isbn = '143573338X'". If I used the auto-increment key, I would need to create a connection to search for isbn, and the query would be more complex and slow, for example, "select count (*) from book join sale using (bookid), where isbn = '143573338X'". (And I can assure you that since this particular ISBN is for my book, the number of sales records is very small, so combining and reading one additional record is a big percentage difference!)
Another advantage of natural keys is that when you have to work with a database and you look at records that refer to this table by keywords, it is easy to see which record they refer to.
On the other hand, if there is no good, obvious natural key, do not try to fuss along with the madman. I saw people trying to make a natural key by combining the first 6 letters of a customer’s name, his year of birth, and his zip code, and then pray for it to be unique. Such stupidity just creates problems for you. Often people end up taking a serial number to make it unique anyway, and at that point, why bother? Why not just use the sequence number on its own as the key?
Jay 02 Feb 2018-10-02T00 : 02
source share