473,385 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Comiting changes(?) With MySQL

Hi,

I have a function to update some data, I run a set of 6 queries, ( all
updates and all on the same table).
I seem to run into problems where the data does not seem to be updated
properly or the update appears to be wrong.

What the function is doing, (try to do anyway), is

given some ID numbers A, B and the same table
I need to swap the values for both items...

C is a arbitrary number used for swapping the values...

update tablex set ID_NUMBER = C where ID_NUMBER = A
update tablex set SUBID_NUMBER= C where SUBID_NUMBER = A

update tablex set ID_NUMBER = A where ID_NUMBER = B
update tablex set SUBID_NUMBER =A where SUBID_NUMBER = B

update ID_NUMBER = B where ID_NUMBER = C
update SUBID_NUMBER =B where SUBID_NUMBER = C

To me that is not a very efficient way of doing things, would there be a
better query for swapping ID_NUMER/SUBIDNUMBER like code above?

Would I need to 'COMIT' the changes to ensure that they do not get mangled
by another query using the same table, (straight after that function)?

Many thanks

Sims
Jul 17 '05 #1
1 1443
"Sims" <si*********@hotmail.com> wrote in message
news:<2f************@uni-berlin.de>...

I have a function to update some data, I run a set of 6 queries, ( all
updates and all on the same table).
I seem to run into problems where the data does not seem to be updated
properly or the update appears to be wrong.

What the function is doing, (try to do anyway), is
given some ID numbers A, B and the same table
I need to swap the values for both items...

To me that is not a very efficient way of doing things, would there be a
better query for swapping ID_NUMER/SUBIDNUMBER like code above?
Not off the top of my head...
Would I need to 'COMIT' the changes to ensure that they do not get mangled
by another query using the same table, (straight after that function)?


The purpose of transactions is not to prevent "mangling by another
query". It is to ensure that either all queries in a batch are
executed or none is. In your case it seems to be a good idea to
do something like this:

BEGIN;
UPDATE tablex SET ID_NUMBER = C where ID_NUMBER = A;
UPDATE tablex SET SUBID_NUMBER = C where SUBID_NUMBER = A;
UPDATE tablex SET ID_NUMBER = A where ID_NUMBER = B;
UPDATE tablex SET SUBID_NUMBER = A where SUBID_NUMBER = B;
UPDATE tablex SET ID_NUMBER = B where ID_NUMBER = C;
UPDATE tablex SET SUBID_NUMBER = B where SUBID_NUMBER = C;
COMMIT;

Cheers,
NC
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
8
by: William Drew | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.databases.mysql This is an invitation to discuss the following proposal to create newsgroup comp.databases.mysql. Please note that YOU...
0
by: kayra | last post by:
Hi all, I want to get your opinions on how to increase available/free memory and performance on a heavy volume database server. I have MySQL 4.0.13 running on RH 7.2 replicated to another RH...
4
by: Gordon Burditt | last post by:
What's the easiest way to copy a row from one table to another (with the same schema), without knowing in advance the number and types of the columns? The problem: I have several sets of tables...
3
by: eieiohh | last post by:
MySQL 3.23.49 PHP 4.3.8 Apache 2.0.51 Hi All! Newbie.. I had a CRM Open Source application installed and running. Windows Xp crashed. I was able to copy the contents of the entire hard...
39
by: windandwaves | last post by:
Hi Folk I have to store up to eight boolean bits of information about an item in my database. e.g. with restaurant drive-through facility yellow windows
4
by: Bob Alston | last post by:
Anyone have experience with converting an access app from Jet database to Mysql? I am specifically looking for any changes I would have to make to my access forms, queries, modules, vba code, etc....
3
by: sp3d2orbit | last post by:
I've read the MySQL licensing material and what I've found online, but I'm still unclear about when I have to pay MySQL for a license. Scenario: I've created an application that stores some data...
0
Coldfire
by: Coldfire | last post by:
Since i cannot show the differences in a two-column like table. I am first putting MS SQL Server 2005 and then MySQL 5.x. MS SQL Server 2005 Brief Overview - SQL Server is a full-fledged...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.