Home > database >  How to set up the combination of the two fields can't repeat?
How to set up the combination of the two fields can't repeat?

Time:03-06

The combination of field A and B cannot repeat, the two fields are not the primary key, don't want to write code in the application layer, can be realized through database configuration?

CodePudding user response:

Set combination is the only key, unique key (` a `, ` ` b)

CodePudding user response:

To these two fields as the only index, UNIQUE KEY ` uniq_user ` (` user_id `, ` user_type `)
  • Related