Answers

Question and Answer:

  Home  MS SQL Server

⟩ Is the Order of Columns in the SET Clause Important in MS SQL Server?

The answer is NO. The order of columns in the SET clause of the UPDATE statement is NOT important. You probably already noticed from the previous tutorial. There is a BIG DIFFERENCE among SQL Server, MySQL and Oracle on update multiple columns with previous values:

* SQL Server provides you the existing values from the database on columns names used in new value expressions. So the order of columns in the SET clause is NOT important

* MySQL provides you the updated values on columns names used in new value expressions. So the order of columns in the SET clause is important.

* Oracle provides you the existing values from the database on columns names used in new value expressions. So the order of columns in the SET clause is NOT important

Here is a good tutorial exercise:

SELECT * FROM ggl_links

-- Check the old values

SELECT * FROM ggl_links WHERE url = 'www.rendc.org'

GO

id url notes counts created

101 www.rendc.org Good. 999 2006-04-30

-- Update "id" before "counts"

UPDATE ggl_links SET id = id+200, counts = id*2

WHERE url = 'www.rendc.org'

GO

(1 row(s) affected)

 125 views

More Questions for you: