473,396 Members | 1,683 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,396 software developers and data experts.

Update order

Hello,

I'm using SS2000 on NT4.

If I run the following query, is it garanteed that the field
"OldField1Value" will hold the value Field1 had before the query was run?

UPDATE MyTable
SET Field1 = 42,
OldField1Value = Field1
.... and in this query?

UPDATE MyTable
SET OldField1Value = Field1,
Field1 = 42


Jul 20 '05 #1
2 3516
Yannick,

Yes. OldField1Value will be set to the value of Field1 prior to the query's
execution in both cases. Think of all the columns in being updated in the
same instant rather than one after the other. The order in which you
specify the columns after SET is not significant.

Try this for a demonstration:

CREATE TABLE foo (
code CHAR(1) NOT NULL PRIMARY KEY,
c1 INT NOT NULL,
c2 INT NOT NULL,
c3 INT NOT NULL);

INSERT INTO foo VALUES ('A',1,3,7);
INSERT INTO foo VALUES ('B',2,5,8);

UPDATE foo
SET c1=c2+1, c2=c3+1, c3=c1+1;
"Yannick Turgeon" <no****@nowhere.com> wrote in message
news:xW*******************@news20.bellglobal.com.. .
Hello,

I'm using SS2000 on NT4.

If I run the following query, is it garanteed that the field
"OldField1Value" will hold the value Field1 had before the query was run?

UPDATE MyTable
SET Field1 = 42,
OldField1Value = Field1
... and in this query?

UPDATE MyTable
SET OldField1Value = Field1,
Field1 = 42

Jul 20 '05 #2
I just realised that your test exclude any possible "lucky" sequence. This
is a definite confirmation!

"Rich Dillon" <ri********@mindspring.com> wrote in message
news:bg**********@slb3.atl.mindspring.net...
Yannick,

Yes. OldField1Value will be set to the value of Field1 prior to the query's execution in both cases. Think of all the columns in being updated in the
same instant rather than one after the other. The order in which you
specify the columns after SET is not significant.

Try this for a demonstration:

CREATE TABLE foo (
code CHAR(1) NOT NULL PRIMARY KEY,
c1 INT NOT NULL,
c2 INT NOT NULL,
c3 INT NOT NULL);

INSERT INTO foo VALUES ('A',1,3,7);
INSERT INTO foo VALUES ('B',2,5,8);

UPDATE foo
SET c1=c2+1, c2=c3+1, c3=c1+1;
"Yannick Turgeon" <no****@nowhere.com> wrote in message
news:xW*******************@news20.bellglobal.com.. .
Hello,

I'm using SS2000 on NT4.

If I run the following query, is it garanteed that the field
"OldField1Value" will hold the value Field1 had before the query was run?
UPDATE MyTable
SET Field1 = 42,
OldField1Value = Field1
... and in this query?

UPDATE MyTable
SET OldField1Value = Field1,
Field1 = 42


Jul 20 '05 #3

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

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
0
by: doomsday123 | last post by:
I have a gridview that displays a ORDER_ID in the first column and then I add 2 button columns on the end of it to approve or deny the order. If they approve it I want to update the database row's...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
5
by: handoyo | last post by:
Hi all,i'm trying to show updated data in existing html td.. For example i got column that show last modified datetime,then i want to update data again,the column will changed to current time without...
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: 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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.