Duplicate Keys

Post here if you need help with SQL.
Post Reply
wrichards8
Posts: 66
Joined: Thu Jan 12, 2012 3:54 pm
Contact:

Duplicate Keys

Post by wrichards8 »

II have a table which looks like

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;
and then I add constraints to it, making a row into a unique key
ALTER TABLE `some_table` ADD UNIQUE `vote` (`field_one`,`field_two`,`field_three`, `field_four`);
In order to test my setup, I am running the following query:
 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

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?
wrichards8
Posts: 66
Joined: Thu Jan 12, 2012 3:54 pm
Contact:

Re: Duplicate Keys

Post by wrichards8 »

Worked it out now :P
Post Reply