SELECT 返回数据,但 UPDATE 给出受影响的行:0
这是数据:
CREATE TABLE `Charlies_Sierra_Papa` (
`Mike` int(5) default NULL,
`cpf` char(11) default NULL,
`idFoxtrot` int(3) default NULL,
) ENGINE=MyISAM AUTO_INCREMENT=254098 DEFAULT CHARSET=utf8;
INSERT INTO `Charlies_Sierra_Papa` VALUES ('1', '12345678910', '12');
INSERT INTO `Charlies_Sierra_Papa` VALUES ('2', '11121314157', '12');
INSERT INTO `Charlies_Sierra_Papa` VALUES ('3', '57585960610', '12');
CREATE TABLE `Charlies` (
`idCharlie` int(20) NOT NULL auto_increment,
`cpf` varchar(11) NOT NULL default ''
PRIMARY KEY (`idCharlie`),
UNIQUE KEY `cpf` (`cpf`),
UNIQUE KEY `idCharlie` (`idCharlie`),
) ENGINE=MyISAM AUTO_INCREMENT=264670 DEFAULT CHARSET=latin1;
INSERT INTO `Charlies` VALUES ('1', '12345678910');
INSERT INTO `Charlies` VALUES ('2', '11121314157');
INSERT INTO `Charlies` VALUES ('3', '57585960610');
CREATE TABLE `Mike` (
`Mike` int(5) unsigned zerofill NOT NULL auto_increment,
`idCharlie` int(11) NOT NULL default '0',
PRIMARY KEY (`Mike`),
UNIQUE KEY `idCharlie` (`idCharlie`)
) ENGINE=MyISAM AUTO_INCREMENT=12043 DEFAULT CHARSET=latin1;
INSERT INTO `Mike` VALUES ('00001', '51214');
INSERT INTO `Mike` VALUES ('00002', '174135');
INSERT INTO `Mike` VALUES ('00003', '203553');
这是 SELECT 和 UPDATE:
UPDATE Charlies_Sierra_Papa AS csp, Charlies AS Cha, Mike_oc AS Mik
SET csp.cpf = cast(Cha.cpf AS char(11))
WHERE csp.cpf = Cha.cpf
AND Cha.idCharlie = Mik.idCharlie
AND csp.Mike = Mik.Mike
AND csp.idFoxtrot = 16
SELECT * FROM Charlies_Sierra_Papa AS csp, Charlies AS Cha, Mike_oc AS Mik
/*SET csp.cpf = cast(Cha.cpf AS char(11))*/
WHERE csp.cpf = Cha.cpf
AND Cha.idCharlie = Mik.idCharlie
AND csp.Mike = Mik.Mike
AND csp.idFoxtrot = 16
我的问题是:SELECT 返回预期值,但是当我运行它时,UPDATE 给了我一个恼人的“Affected rows: 0”。
有什么线索吗?
Here's the data:
CREATE TABLE `Charlies_Sierra_Papa` (
`Mike` int(5) default NULL,
`cpf` char(11) default NULL,
`idFoxtrot` int(3) default NULL,
) ENGINE=MyISAM AUTO_INCREMENT=254098 DEFAULT CHARSET=utf8;
INSERT INTO `Charlies_Sierra_Papa` VALUES ('1', '12345678910', '12');
INSERT INTO `Charlies_Sierra_Papa` VALUES ('2', '11121314157', '12');
INSERT INTO `Charlies_Sierra_Papa` VALUES ('3', '57585960610', '12');
CREATE TABLE `Charlies` (
`idCharlie` int(20) NOT NULL auto_increment,
`cpf` varchar(11) NOT NULL default ''
PRIMARY KEY (`idCharlie`),
UNIQUE KEY `cpf` (`cpf`),
UNIQUE KEY `idCharlie` (`idCharlie`),
) ENGINE=MyISAM AUTO_INCREMENT=264670 DEFAULT CHARSET=latin1;
INSERT INTO `Charlies` VALUES ('1', '12345678910');
INSERT INTO `Charlies` VALUES ('2', '11121314157');
INSERT INTO `Charlies` VALUES ('3', '57585960610');
CREATE TABLE `Mike` (
`Mike` int(5) unsigned zerofill NOT NULL auto_increment,
`idCharlie` int(11) NOT NULL default '0',
PRIMARY KEY (`Mike`),
UNIQUE KEY `idCharlie` (`idCharlie`)
) ENGINE=MyISAM AUTO_INCREMENT=12043 DEFAULT CHARSET=latin1;
INSERT INTO `Mike` VALUES ('00001', '51214');
INSERT INTO `Mike` VALUES ('00002', '174135');
INSERT INTO `Mike` VALUES ('00003', '203553');
And here are the SELECT and the UPDATE:
UPDATE Charlies_Sierra_Papa AS csp, Charlies AS Cha, Mike_oc AS Mik
SET csp.cpf = cast(Cha.cpf AS char(11))
WHERE csp.cpf = Cha.cpf
AND Cha.idCharlie = Mik.idCharlie
AND csp.Mike = Mik.Mike
AND csp.idFoxtrot = 16
SELECT * FROM Charlies_Sierra_Papa AS csp, Charlies AS Cha, Mike_oc AS Mik
/*SET csp.cpf = cast(Cha.cpf AS char(11))*/
WHERE csp.cpf = Cha.cpf
AND Cha.idCharlie = Mik.idCharlie
AND csp.Mike = Mik.Mike
AND csp.idFoxtrot = 16
my problem is: the SELECT returns the expected values, but the UPDATE gives me an annoying "Affected rows: 0" when I run it.
Any clues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个微不足道的错误:
我正在尝试更新 csp.cpf = Cha.cpf
但我也绑定 csp.cpf = Cha.cpf
所以,没有更新行,也没有雪茄。
It's a trivial error:
I'm trying to UPDATE csp.cpf = Cha.cpf
but I'm also tying csp.cpf = Cha.cpf
so, no rows updated and no cigar.