How to restrict a column value in SQLite / MySQL

后端 未结 5 1974
日久生厌
日久生厌 2020-12-14 18:03

I would like to restrict a column value in a SQL table. For example, the column values can only be \"car\" or \"bike\" or \"van\". My question is how do you achieve this in

5条回答
  •  庸人自扰
    2020-12-14 18:21

    For MySQL, you can use the ENUM data type.

    column_name ENUM('small', 'medium', 'large')

    See MySQL Reference: The ENUM Type

    To add to this, I find it's always better to restrict on the DB side AND on the app side. An Enum plus a Select box and you're covered.

提交回复
热议问题