Have you ever used an application or filled out a web form with the radio buttons and checkboxes depicted below?
Source: Google Image.
Typically, the values for radio buttons are fixed, and you can only select one from the available options. In the database, the column is restricted to that set of items so that an incorrect value cannot be entered. In these scenarios, we use the ENUM datatype and provide a list of the acceptable items for the column.
Example:
CREATE TABLE tbOrders (
iOrderID INT,
OrderDate DATETIME,
OrderStatus ENUM(‘Delivered’, ‘Cancelled’, ‘Under Process’));
The checkbox items, on the other hand, allow you to choose many items at once. The database column that logs these values is typically set with the SET datatype, allowing for multiple values to be entered into a single cell.
Example:
CREATE TABLE User_Preferences(
user_preferences_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
userid INT,
areas_of_interests SET(‘Music’,’Movies’,’Sports’,’Travel’,’Technology’,’Dining’));
In simple words,
Radio fields = ENUM = choose only one from the permitted values.
Checkbox fields = SET = choose multiple values at once for a single cell.
Hope you find this article helpful.