How to write MySQL constraints for male or female?
In MySQL, you can use ENUM constraint to restrict a field to only have one of the specified values. For example, to constrain a field to only have values of ‘male’ or ‘female’, you can use ENUM(‘male’, ‘female’).
The following table will be created to store user information, with columns for user ID, name, and gender, ensuring that the name is not empty and the gender is either male or female.
In the examples provided, the users table contains fields for id, name, and gender. The gender field is of type ENUM and can only store two values, ‘male’ or ‘female’, and cannot be empty.