Is it wrong to have text as a primary key in a SQLite database? I heard that this is bad for performance reasons, is that true?
I have never heard anyone use a row as the primary key in a table. For me (and I sincerely hope for others) a very ugly practice with very low productivity.
If you will use the string as the primary key, you need to think about the “few” things:
- Will a 3-character combination suffice?
- Or should I use 5 characters?
Here, each line should have the same format (of course, readability), and also be unique . Oh! Here is the next “copy” -> you need to create some “unique line generator” that will generate a unique identifier for line 1 2 .
And also there are the following issues to consider:
- Longer lines
= automatically harder and harder to compare - The size of the table increases dramatically because it is pretty clear that the row is much larger as a number
- The number of rows is crazy to use a row as the primary key if you table can contain 1000 rows
This is a more complex topic, but I would like to say that OK, for very small tables, you could use rows as the primary key (if that makes sense), but if you look at the disadvantages, this is a much more efficient technique for using the number as primary key!
And what is a conclusion?
I do not recommend using the string as the primary key. It has more disadvantages as advantages (does it really have any advantage?).
Using a number as a primary key is much better (I'm afraid to say which is better).
And will rowid be used as the actual primary key in this case?
If you use the string as primary, not.
1 In real lines, rarely unique.
2 Of course, you can say that you can create an identifier on behalf of an element in a string, but it is again spaghetti code (elements can have the same name).
Simon dorociak
source share