how to add composite unique to a column in the tab

2019-06-24 05:50发布

问题:

I have a table:

  1. user_id int Composite Unique (deal_id + user_id+deal_type).
  2. deal_id int
  3. deal_type varchar.
  4. created_on datetime.

This is my table. I want to create a composite unique on the user_id column so that a single user can have only unique deal_id for each deal_type.

How to make composite unique for in mysql phpmyadmin.

回答1:

ALTER TABLE my_table ADD UNIQUE KEY (user_id, deal_type, deal_id);