II have a table which looks like
[syntax=sql]CREATE TABLE IF NOT EXISTS `some_table`
(
`field_one` CHAR(6) NOT NULL,
`field_two` INT(1) NOT NULL,
`field_three` INT(4) NOT NULL,
`field_four` INT(10) NOT NULL
)
ENGINE = InnoDB;[/syntax]
and then I add constraints to it, making a row into a unique key
[syntax=sql]ALTER TABLE `some_table` ADD UNIQUE `vote` (`field_one`,`field_two`,`field_three`, `field_four`);[/syntax]
In order to test my setup, I am running the following query:
[syntax=sql] INSERT INTO `some_table` (`field_one`, `field_two`, `field_three`, `field_four`) VALUES ('C8696E', 1, 1, 0) ON DUPLICATE KEY UPDATE `field_three` = `field_three` + 1[/syntax]
First of all it created one row and then a second row. The first row has `field_three` set to 1 and the second row has `field_three` set as 2 but when I press refresh again, I get this error #1062 - Duplicate entry 'C8696E-1-2-0' for key 'vote'
What am I doing wrong?
Duplicate Keys
-
- Posts: 66
- Joined: Thu Jan 12, 2012 3:54 pm
- Contact:
-
- Posts: 66
- Joined: Thu Jan 12, 2012 3:54 pm
- Contact:
Re: Duplicate Keys
Worked it out now