2012-12-25 77 views
2

爲什麼在我的MySQL表#1062 - 重複錄入 '0' 鍵 'username_clean'

CREATE TABLE IF NOT EXISTS `phpbb_users_copy` (
    `username` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', 
    `username_clean` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', 
    `user_password` varchar(40) COLLATE utf8_bin NOT NULL DEFAULT '', 
    `user_email` varchar(100) COLLATE utf8_bin NOT NULL DEFAULT '' 
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; 

當我做一個查詢

UPDATE phpbb_users 
SET  username_clean ='username' AND 
     user_password ='$H$76MZf0m0LJ5T1Tkz/' AND 
     user_email ='[email protected]' AND 
     username ='Username' 
WHERE username_clean ='username' 

我得到一個錯誤:

#1062 - Duplicate entry '0' for key 'username_clean' 
+0

您確定,您的UPDATE語法正確嗎? –

+0

你是什麼意思的語法正確 –

+1

查看@JW的答案... –

回答

7

當使用UPDATE語句時,需要將要更新的列分隔爲COMMA而不是AND

UPDATE phpbb_users 
SET  username_clean ='username' , 
     user_password ='$H$76MZf0m0LJ5T1Tkz/' , 
     user_email ='[email protected]' , 
     username ='Username' 
WHERE username_clean ='username' 

UPDATE

請大家注意,您在表更新phpbb_users_copyphpbb_users不能及的。

相關問題