sinesine sinesine - 1 year ago 71
MySQL Question

MySQL data type for a field with only two possible options

I'm trying to work out which data type to use for a field in my database that can only be one of two options: 'dual' or 'solo'.

I realise that this is essentially Boolean but I can't use tinyint(1) because the inputs are not numbers.

If anyone could give me an idea of what to use in this situation it would be greatly appreciated :)

Answer Source

You can use ENUM

colname ENUM('dual', 'solo')

Internally it will be stored as a TINYINT, but when storing and retrieving it will use the strings.

Or you could use TINYINT. The terms "dual" and "solo" refer to 2 and 1 participants, so you could have

participants TINYINT(1)

and store 1 for solo and 2 for dual.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download