How to restrict a column value in SQLite / MySQL

后端 未结 5 1989
日久生厌
日久生厌 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:12

    Add a new table containing these means of transport, and make your column a foreign key to that table. New means of transport can be added to the table in future, and your column definition remains the same.

    With this construction, I would definitively choose to regulate this at the DB level, rather than that of the application.

提交回复
热议问题