| >Enums are for non user-configurable values In the systems I work with most coded values are user configurable. >But those should have an auto-integer primary key and if you need the description, join for it. Not ergonomic now when querying data or debugging things like postal state are 11 instead of 'NY' select * from addresses where state = 11, no thanks. Your whole results set becomes a bunch of ints that can be easily transposed causing silly errors. Of course I have seen systems that use guids to avoid collision, boy is that fun, just use varchar or char if your penny pinching and ok with fixed sizes. >the length of the string is stored as an int No it's stored as a smallint 2 bytes. So a single character code is 3 bytes rather than a 4 byte int. 2 chars is the same as an int. They do not complicate storage access in any meaningful way. You could use smallint or tinyint for your primary key and I could use char(2) and char(1) and get readable codes if I wanted to really save space. |
Sure they do, because now your row / index is variable length rather than fixed length. Way more complicated. Even 3 bytes is way more complicated to deal with than 4 bytes.
> select * from addresses where state = 11, no thanks.
I will agree that isn't fun. Is it still the trade off I do make? Absolutely. And it's not really that big of a problem; I just do a join. It also helps prevent people from using codes instead of querying the database for the correct value -- what's the point of user-configuration of someone hard-codes 'NY' in a query or in the code.