MariaDB事务尝试出错

时间:2017-08-29 20:38:15

标签: mariadb dbeaver

我试图在Fedora 25和DBeaver上的MariaDB 10.1.25上执行此事务作为sql编辑器。

每个查询都可以正常工作,但是当它们在事务块上包装时总是会失败。

BEGIN;
INSERT INTO quality.tb_account (email, password, registration_date, active, screen_name)
      VALUES ('user11@email.com', 'password', CURRENT_DATE(), TRUE, 'user11');
INSERT INTO quality.tb_account_roles (account_id, role_id)
      VALUES  (LAST_INSERT_ID(), 1);
COMMIT;

错误是下一个错误:

SQL Error [1064] [42000]: (conn:2) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSERT INTO quality.tb_account (email, password, registration_date, active, scre' at line 2
Query is : BEGIN;
INSERT INTO quality.tb_account (email, password, registration_date, active, screen_name) VALUES ('user11@email.com', 'password', CURRENT_DATE(), TRUE, 'user11');
INSERT INTO quality.tb_account_roles (account_id, role_id) VALUES (LAST_INSERT_ID(), 1);
COMMIT
  (conn:2) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSERT INTO quality.tb_account (email, password, registration_date, active, scre' at line 2
Query is : BEGIN;
INSERT INTO quality.tb_account (email, password, registration_date, active, screen_name) VALUES ('user11@email.com', 'password', CURRENT_DATE(), TRUE, 'user11');
INSERT INTO quality.tb_account_roles (account_id, role_id) VALUES (LAST_INSERT_ID(), 1);
COMMIT
    org.mariadb.jdbc.internal.util.dao.QueryException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSERT INTO quality.tb_account (email, password, registration_date, active, scre' at line 2
Query is : BEGIN;
INSERT INTO quality.tb_account (email, password, registration_date, active, screen_name) VALUES ('user11@email.com', 'password', CURRENT_DATE(), TRUE, 'user11');
INSERT INTO quality.tb_account_roles (account_id, role_id) VALUES (LAST_INSERT_ID(), 1);
COMMIT

我做错了什么?为什么每个查询单独工作但不能一起工作?

1 个答案:

答案 0 :(得分:0)

您必须自己发出每个SQL语句 - 不要尝试将它们连接在一起。

请注意,它说" ...附近' INSERT ..."这意味着它到了&#34 ;;"但之后不喜欢找东西。