#1062 - 密钥'username_clean'重复输入'0'

时间:2012-12-25 13:04:39

标签: mysql sql sql-update

为什么在我的MySQL表中

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 ='2mlrfc4b.wmk@email.com' AND 
        username ='Username' 
WHERE username_clean ='username'

我收到错误:

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

1 个答案:

答案 0 :(得分:7)

使用UPDATE语句时,您需要将要更新的列分隔为COMMA而不是AND

UPDATE  phpbb_users 
SET     username_clean ='username' ,
        user_password ='$H$76MZf0m0LJ5T1Tkz/' , 
        user_email ='2mlrfc4b.wmk@email.com' ,
        username ='Username' 
WHERE   username_clean ='username'

<强>更新

请注意,您正在更新phpbb_users表,而不是phpbb_users_copy