We help IT Professionals succeed at work.
Get Started

Problem with ON DUPLICATE KEY UPDATE

Eddie Shipman
on
294 Views
Last Modified: 2012-05-12
I have a table defined like this:
CREATE TABLE `sync_orders_attempts` (
	`attempt_id` INT(11) NOT NULL AUTO_INCREMENT,
	`incremental_id` INT(11) NULL DEFAULT NULL,
	`order_id` INT(11) NULL DEFAULT NULL,
	`attempt_time` DATETIME NULL DEFAULT NULL,
	`raw_response` TEXT NULL,
	`update_response` TEXT NULL,
	`soap_data` VARCHAR(5000) NULL DEFAULT NULL,
	`update_data` TEXT NULL,
	INDEX `Index 1` (`attempt_id`, `incremental_id`, `order_id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=MyISAM
ROW_FORMAT=DEFAULT

Open in new window


When running an insert on duplicate key update query, it is ignoring the duplicate key.
INSERT INTO SYNC_ORDERS_ATTEMPTS (`incremental_id`, 
                                  `order_id`, 
                                  `raw_response`, 
                                  `update_response`, 
                                  `soap_data`, 
                                  `update_data`,  
                                  `attempt_time`) 
                          VALUES (0,              
                                  0,
                                  'XXX',
                                  'XXXXXX',
                                  'XXXXXXX',
                                  'XXXXXXXXXX',
                                  now())
ON DUPLICATE KEY UPDATE `incremental_id`  = VALUES(`incremental_id`), 
                        `order_id`        = VALUES(`order_id`), 
                        `raw_response`    = VALUES(`raw_response`), 
			`update_response` = VALUES(`update_response`), 
                        `soap_data`       = VALUES(`soap_data`), 
			`update_data`     = VALUES(`update_data`), 
			`attempt_time`    = VALUES(`attempt_time`)

Open in new window

If I remove the autoinc from the attempt_id column and the index, it still ignores the duplicate key.
How do I fix this?
Comment
Watch Question
Senior Developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE