Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

395
Views
SQL Query works in MySQL Workbench but not in code

I am trying to write a transaction with two INSERT INTOs that looks like this:

BEGIN;
INSERT INTO users VALUES('123', 0, 0, 0);
INSERT INTO inventory VALUES('123', 0, 0, 0, 0, 0);
COMMIT;

This Query works fine in the MySQL Workbench but not in my Code that I wrote in JavaScript:

app.post("/", (req, res) => {
    db.query(`BEGIN;
              INSERT INTO users VALUES('123', 0, 0, 0);
              INSERT INTO inventory VALUES('123', 0, 0, 0, 0, 0);
              COMMIT;`, (err, result) => {
        if (err) throw err
        res.status(200).send(result)
    })
})

I am getting the Error: 1064, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use

I'm using the mysql2 Package in my JavaScript Backend.

Does anybody know why this problem occurs?

EDIT: I even tried START TRANSACTION instead of BEGIN

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!