0
我有一個表的MySQL對重複密鑰更新麻煩
CREATE TABLE IF NOT EXISTS `b_sale_order_props_value` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`ORDER_ID` int(11) NOT NULL,
`ORDER_PROPS_ID` int(11) DEFAULT NULL,
`NAME` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`VALUE` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`CODE` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `IX_SOPV_ORD_PROP_UNI` (`ORDER_ID`,`ORDER_PROPS_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1921 ;
我做一個查詢
INSERT INTO `b_sale_order_props_value`
SET `ORDER_ID`=316,
`ORDER_PROPS_ID`=30,
`NAME`='ADDRES',
`VALUE`='Test addres'
ON DUPLICATE KEY UPDATE `NAME`='ADDRES',`VALUE`='Test addres';
返回一個錯誤
Duplicate entry '316-30' for key 'IX_SOPV_ORD_PROP_UNI'
如何解決這個麻煩?
無法重現:[sqlfiddle(http://sqlfiddle.com/#!2/88845/1/0) – lanzz 2012-08-01 14:15:52