我试图使下面的事务正常工作,但我在SELECT附近得到一个mysql错误。我已经检查过所有的列名是否正确。
错误消息
您的SQL语法出现了错误;请检查与您的MySQL服务器版本对应的手册,以便在第2行使用接近“插入文章”(catid、内容、标题、关键字、isactive)的正确语法(SELEC)。
SQL
START TRANSACTION;
INSERT INTO articles (catid,content,title,keywords,isactive)
(SELECT 1, pendingarticles.content, pendingarticles.title,
pendingarticles.keywords, 1
FROM pendingarticles
WHERE pendingarticles.id=1);
DELETE FROM pendingarticles WHERE id=1;
COMMIT;更新
代码本身是有效的。插入-选择部分和删除部分.交易有点不对劲。也许是;?还是我的db服务器不能进行事务处理?
发布于 2013-07-18 15:14:38
MyISAM引擎不支持事务。MyIsam引擎事务支持
要支持事务,您必须更改引擎f.e。敬InnoDB。设置存储引擎
发布于 2013-07-18 14:10:18
你想:
INSERT INTO articles (catid,content,title,keywords,isactive)
SELECT 1,pendingarticles.content,pendingarticles.title,
pendingarticles.keywords,1
FROM pendingarticles
WHERE pendingarticles.id=1;
DELETE FROM pendingarticles WHERE id=1; 您提供的额外一组括号是不必要的。
发布于 2013-07-18 14:11:32
我相信“选择”周围的括号是不必要的。
http://dev.mysql.com/doc/refman/5.6/en/insert.html
START TRANSACTION;
INSERT INTO articles (catid,content,title,keywords,isactive)
SELECT 1, pendingarticles.content, pendingarticles.title,
pendingarticles.keywords, 1
FROM pendingarticles
WHERE pendingarticles.id=1;
DELETE FROM pendingarticles WHERE id=1;
COMMIT; https://stackoverflow.com/questions/17725714
复制相似问题