I have been looking at the datatypes for MySQL but there is nothing really that I can see that mandates that input is either one thing or another. E.g. "option1" or "option2".
How might I do something like this when creating a table?
You can use enum datatype for restricting input within a range of values. Below is a sample table that shows the usage.
CREATE TABLE Sample
(
id int auto_increment primary key,
options enum('option1', 'option2')
);
The options field will only accept NULL, option1 OR option2 values. However, you can mark it NOT NULL as well.
You can further read the doco here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With