此特定查询应该将用户输入数据库。
此查询并不总是插入firstname和lastname字段的值以及其他字段。对于一些插入,firstname和lastname为空,对于其他插入,firstname和lastname按预期工作。
INSERT INTO `users` (mobile, passwordHash, firstname, lastname, ent_id, email ) VALUES ('913800341127', '678a1491514b7f1006d605e9161946b1', 'nat', 'sam', '108', NULL) ON DUPLICATE KEY UPDATE `firstname` = VALUES(firstname),`lastname` = VALUES(lastname)
相关信息:
CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `tag` varchar(5) NOT NULL default 'ind', `username` varchar(50) default NULL, `firstname` varchar(100) default NULL, `lastname` varchar(100) default NULL, `passwordhash` varchar(255) NOT NULL, `secretq` varchar(255) default NULL, `secreta` varchar(100) default NULL, `email` varchar(50) default NULL, `mobile` varchar(13) default NULL, `last_login` datetime default NULL, `ent_id` bigint(20) NOT NULL default '1', `is_inactive` tinyint(1) NOT NULL COMMENT 'Whether the user is active or not', PRIMARY KEY (`id`), UNIQUE KEY `mobile_2` (`mobile`,`ent_id`), UNIQUE KEY `email_2` (`email`,`ent_id`), KEY `username` (`username`), KEY `ent_id` (`ent_id`,`tag`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1
答案 0 :(得分:1)
语法错误应该是:
ON DUPLICATE KEY UPDATE firstname = 'nat',lastname = 'sam'