Reputation: 4476
I have a table Drivers
with columns Id
, Name
, Status
. In C# I have an enum for driver status
public enum DriverStatus
{
Online = 0,
Offline = 1,
Busy = 2,
SoonFree = 3
}
Currently in the database, I use a varchar
data type for the Status
column and this means I have records like:
1 John Online
2 Elsy Offline
This seams to be bad and I think this need to be changed to status column type tinyint
because:
Tinyint
is only one byte size with range 0-255.varchar
so it sorts in alphabetical order not in enum priorities.DriverStatus
enum value name I also need to update database to be consistent.Then I asked others why we use varchar
for enum columns the only reason was that it is easier to debug as you see text not number like 0 or 3. Is where any really good reasons to have strings for enums in the database?
Upvotes: 0
Views: 1317
Reputation: 33738
It is absolutely better to use a Lookup Table for enum values.
Advantages:
Upvotes: 2