Could I make a column in a table only allows one 'true' value and all other rows should be 'false'

后端 未结 4 831
遥遥无期
遥遥无期 2020-12-15 17:04

In MySQL, Can I put a restriction like below at database level?

I need to make sure 1. a specific column can only take either \'true\' or \'false\' values. 2. and e

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 17:46

    Rather than having the boolean attribute in the table, you could have another table that contains one row and points to the row in the original table that you consider true.

    Changing the true value is a matter of updating the foreign key in the TrueRow table.

提交回复
热议问题