SELECT 返回数据,但 UPDATE 给出受影响的行:0

发布于 2024-12-09 14:54:50 字数 1851 浏览 0 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

面犯桃花 2024-12-16 14:54:50

这是一个微不足道的错误:

我正在尝试更新 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文