Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9021243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:12:43+00:00 2026-06-16T05:12:43+00:00

START TRANSACTION; SELECT @A:=SUM(salary) FROM table1 WHERE type=1 FOR UPDATE; UPDATE table2 SET summary=@A

  • 0
START TRANSACTION;
SELECT @A:=SUM(salary) FROM table1 WHERE type=1 FOR UPDATE;
UPDATE table2 SET summary=@A WHERE type=1;
COMMIT;

I have taken this query directly from the MySQL official documentation and I am wondering certain aspects (I added myself the FOR UPDATE). Supposing that there is another user that already has a lock on the record. In that case the update should fail. If that were to happen I am wanting for sure a way to display to my user a message box that will alert the user that there is a lock on the record. How might I get that information back into PHP? Also wouldn’t this query roll back by default or do I specifically need to add the ROLLBACK?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:12:44+00:00Added an answer on June 16, 2026 at 5:12 am

    You have to reset the value of autocommit variable to OFF / 0 / FALSE.
    Try this:

    SET SESSION autocommit = 0;
    START TRANSACTION;
    SELECT @A:=SUM(salary) FROM table1 WHERE type=1 FOR UPDATE;
    UPDATE table2 SET summary=@A WHERE type=1;
    COMMIT;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In straight mysql script I'd do transactions like this: START TRANSACTION; SELECT @A:=SUM(salary) FROM
Ok, what I have right now is this: START TRANSACTION; SELECT redeemTicketChances FROM userRedeemChances
I have the following code TransitionManager.start(babyPreloader,{type:Fade, direction:Transition.OUT, duration:0.5, easing:Regular.easeOut}); var tempPreloader:DisplayObject = babyPreloader as
QUERY 1: $link = mysql_connect('localhost', 'root', ''); mysql_select_db('rems', $link); mysql_query('SET AUTOCOMMIT=0; START TRANSACTION', $link);
I'm a bit confused by the documentation here. I have a transaction, which start
I'm having a bit of trouble with the following query: START TRANSACTION; SET @LASTID
I want to execute transactions in node-mysql (by executing queries START TRANSACTION, ROLLBACK, COMMIT).
I have an SQL query that groups by transaction type and then sums amount,
I saw few examples over internet of Hibernate using transaction.commit() for select statements. Below
The basic structure of my procedure is: BEGIN START TRANSACTION; .. Query 1 ..

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.