0

I need to make a column in Database Unique but can duplicate if change another column number.

+-----------------------------------+------------+
|               Name                |    Status  | 
+-----------------------------------+------------+
|               XerK                |     1      |    
|               cdya                |     1      |    
|               XerK                |     2      |
|               cdya                |     2      |   
+-----------------------------------+------------+

I need to like this table but no duplicate when status same equal.

Thank you.

Ahmed Mamdouh
  • 285
  • 2
  • 5
  • 18

1 Answers1

0

You can create a unique composite like this

ALTER TABLE `yoourtable` ADD UNIQUE `unique_index`(`Name`, `Status`);

Taken from How do I specify unique constraint for multiple columns in MySQL?

Kartik Prasad
  • 730
  • 7
  • 18
  • 1
    Every time you "take" an old SO answer/solution and paste it into a new question a kitten dies. Please do the right thing which is to delete your answer and flag/vote this question as a duplicate. – mickmackusa Nov 24 '17 at 01:34