2013-02-25 65 views
3

嗨錯誤我得到一個非常非描述性錯誤MariaDB的/ MySQL的非描述語法與更新上重複鍵

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'VALUES (order_site_id, order_id, business_email, business_domain, sm_type, activ' at line 1

這裏的插入/更新

INSERT INTO table 
(
    id, 
    order_site_id, 
    order_id, 
    business_email, 
    business_domain, 
    sm_type, 
    active, 
    code, 
    sm_auth, 
    installed, 
    created, 
    cancelled, 
    uninstalled, 
    updated 
) VALUES (
     1, 
     2, 
     1, 
     '[email protected]', 
     'domain.com', 
     'farce', 
     'N', 
     'a3yhegy', 
     '55f933dad8a389cf760d39df01df923e', 
     '0000-00-00 00:00:00', 
     '2013-02-20 11:21:00', 
     '0000-00-00 00:00:00', 
     '0000-00-00 00:00:00', 
     '2013-02-20 11:21:00' 
    ), (
     2, 
     2, 
     2, 
     '[email protected]', 
     'domain.com', 
     'farce', 
     'N', 
     'e4eqere', 
     '08d2ab294466864d3453201be3e4a391', 
     '0000-00-00 00:00:00', 
     '2013-02-20 11:37:45', 
     '0000-00-00 00:00:00', 
     '0000-00-00 00:00:00', 
     '2013-02-20 11:37:45' 
    ), (
     3, 
     2, 
     3, 
     '[email protected]', 
     'domain.com', 
     'farce', 
     'N', 
     '8yme3ud', 
     'c52b2cf4a6a5ceab503fe71c45d9e5da', 
     '0000-00-00 00:00:00', 
     '2013-02-20 11:38:28', 
     '0000-00-00 00:00:00', 
     '0000-00-00 00:00:00', 
     '2013-02-20 11:38:28' 
    ), (
     4, 
     2, 
     4, 
     '[email protected]', 
     'domain.com', 
     'farce', 
     'N', 
     'zuzuquz', 
     'c30dbfda67a0016d810b774e08e077c8', 
     '0000-00-00 00:00:00', 
     '2013-02-20 11:42:31', 
     '0000-00-00 00:00:00', 
     '0000-00-00 00:00:00', 
     '2013-02-20 11:42:31' 
    ), (
     5, 
     2, 
     5, 
     '[email protected]', 
     'domain.com', 
     'farce', 
     'N', 
     'nyruqu4', 
     'c376194d36d5706a6ca343dc3a06248d', 
     '0000-00-0000:00:00', 
     '2013-02-20 11:43:29', 
     '0000-00-00 00:00:00', 
     '0000-00-00 00:00:00', 
     '2013-02-20 11:43:29' 
) ON DUPLICATE KEY UPDATE VALUES (
    order_site_id, 
    order_id, 
    business_email, 
    business_domain, 
    sm_type, 
    active, 
    code, 
    sm_auth, 
    installed, 
    created, 
    cancelled, 
    uninstalled, 
    updated 
); 

回答

0

你不要在ON DUPLICATE KEY UPDATE中使用VALUES子句。

的語法應該更像UPDATE語法:

INSERT INTO table (id, order_site_id, order_id, ...) 
VALUES (1, 2, 1, ...), (2, 2, 2, ...), ...more tuples... 
ON DUPLICATE KEY UPDATE 
SET order_site_id = <expr>, 
    order_id = <expr>, 
    ...other column assignments... 

http://dev.mysql.com/doc/refman/5.5/en/insert-on-duplicate.html

如果你只是想在一個重複鍵的情況下獨自離開現有的列值,你應該考慮使用INSERT IGNORE,而不是ON DUPLICATE KEY UPDATE,並且沒有更新。

+0

所以我只能設置一次? – ehime 2013-02-25 19:00:46

+0

我用替換,代替,似乎現在正常工作 – ehime 2013-02-25 19:05:59

+1

我已經編輯我的上面的示例更清楚一點。 REPLACE可能適合你。但請記住REPLACE有一些副作用。見http://stackoverflow.com/questions/548541/insert-ignore-vs-insert-on-duplicate-key-update/548570#548570 – 2013-02-25 23:53:28