Unique Constraint with conditions in MYSQL

后端 未结 5 1791
心在旅途
心在旅途 2020-12-18 09:35

In postgres we have a constraint defined that essentially allows us to limit the number of entries in a table with a certain value to one. We created this constraint:

5条回答
  •  春和景丽
    2020-12-18 10:01

    Actually it exists. Most contraints depend on the table Engine. I think InnoDB supports this.

    To do it, you have to add a UNIQUE index with the unique combination:

    ALTER TABLE visitor ADD UNIQUE unique_default_visitor( visitor_uid, list_type );
    

提交回复
热议问题