MySQL – using String as Primary Key

There’s nothing wrong with using a CHAR or VARCHAR as a primary key.

Sure it’ll take up a little more space than an INT in many cases, but there are many cases where it is the most logical choice and may even reduce the number of columns you need, improving efficiency, by avoiding the need to have a separate ID field.

For instance, country codes or state abbreviations already have standardised character codes and this would be a good reason to use a character based primary key rather than make up an arbitrary integer ID for each in addition.

Leave a Comment

tech