Reputation: 53
I have this MySQL Table, the PRIMARY KEY (ID).
ID | COLOR | SIZE
====================
| 1 | RED | 1 |
| 2 | RED | 2 |
| 3 | RED | 3 |
| 4 | GREEN | 1 |
| 5 | GREEN | 2 |
| 6 | BLUE | 1 |
===================
When i insert this row for example
INSERT INTO `test`(`COLOR`, `SIZE`) VALUES (RED',1);
i have a duplicate row 1, RED, 1 and 7, RED, 1 how to avoid this problem?
Thanks
Upvotes: 2
Views: 437
Reputation: 2535
Before you run this empty your table first or remove the duplicate row from your table than run it.
ALTER TABLE `test` ADD UNIQUE (color, size)
Upvotes: 0
Reputation: 133410
You can use alter table
ALTER TABLE `test`
ADD UNIQUE (color, size)
Upvotes: 1