1

我正在尝试使以下事务正常工作,但是在 SELECT 附近出现 mysql 错误。我已经仔细检查了所有列名是否正确。

错误信息

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 2 行的“INSERT INTO 文章(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;

更新

代码本身有效。INSERT INTO - SELECT 部分和 DELETE 部分。交易出了点问题。也许;?或者我的数据库服务器不能进行交易?

4

3 回答 3

2

MyISAM 引擎不支持事务。MyIsam 引擎事务支持

要支持事务,您必须将引擎 fe 更改为 InnoDB。设置存储引擎

于 2013-07-18T15:14:38.223 回答
0

你要:

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-18T14:10:18.443 回答
-1

我相信 Select 周围的括号是不必要的。

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; 
于 2013-07-18T14:11:32.330 回答