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

后端 未结 4 842
遥遥无期
遥遥无期 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:40

    1. a specific column can only take either 'true' or 'false' values.

      Use Datatype for column either boolean or tiny-int

    2 and exactly only one row should be having 'true' value?

    you have to write a query which update all the row columns to false except one you set to true

提交回复
热议问题