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 6671357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:22:45+00:00 2026-05-26T03:22:45+00:00

As a result of a mistake during an import to the a test table

  • 0

As a result of a mistake during an import to the a test table called CUSTOMERS, I found myself needing to switch the values of two columns in SQL Server.

I mistakenly imported the respective values for LASTNAME and FIRSTNAME into the opposite fields (i.e. the customer last name was imported into first name, and vice versa). To remedy this, I ran the following query in SQL Server 2008 R2, of course not expecting it to work:

UPDATE CUSTOMERS
SET LASTNAME=FIRSTNAME, FIRSTNAME=LASTNAME

Surprisingly, it worked! The limited programming experience I’ve had (high school, a few college courses) always followed the paradigm that switching two values required the presence of a third variable to “hold” the value of one of the initial values. In other words, I expected to have to run the following query:

UPDATE CUSTOMERS
SET SOMEOTHERFIELD = LASTNAME
SET LASTNAME = FIRSTNAME
SET FIRSTNAME = SOMEOTHERFIELD

Is this behavior only seen in SQL Server 2008 R2, or does this represent some other underlying facet of relational theory that I’m missing?

  • 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-05-26T03:22:45+00:00Added an answer on May 26, 2026 at 3:22 am

    Its because the way a update works:

    In the set clause are construct a pseudo-table. The rows in this table are build by copying values from the columns that are not mentioned from the original row to a new row. The columns are assigned all at once. That is, the unit of work is a row, not one column at a time. The last step is to delete the olds rows and insert the new rows. Internally, a update is select, delete, insert.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Presumably I have found a mistake in issuing the query result Nearby Search Requests.
What result is right for the following test cases? //Chrome 19 Opera 12 Firefox
please help to find a a mistake: The result is the Query is empty!
I am creating a table based on result from servlet, which contains a checkbox
Ok, second question in two days... i am probably making a newb mistake here
I made a mistake and entered: SELECT * FROM table LIMIT1 instead of SELECT
I did mistake in writing below code but I am not getting the result
I made a huge mistake by mixing result with results and it took me
I have the result of two request, that contains numbers decimal 8,2. I try
... // result is a JSON data passed to this function from outside var

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.