Click here to Skip to main content
13,139,569 members (52,112 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi All,

I want to update multiple columns from multiple tables in a single UPDATE Query...
Just want to do like below query...
UPDATE Table1, Table2
SET Table1.Column1 = 'one' 
,Table2.Column2 = 'two'
FROM Table1 T1, Table2 T2
and = 'id1'

Does Sql Server 2008 provide any mechanism to do so?

If Sql Server 2008 provide such nice approach, please share some links with me!

Posted 8-Mar-13 3:03am
Updated 8-Mar-13 5:28am
Maciej Los255.6K
ryanb31 8-Mar-13 9:31am
Silly question, but have you tried it?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Well, in short - not possible.The same restriction for updateable views:
Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table.

Approach that I believe is optimal: use transactions, possibly wrap your business logic into stored procedures. Code skeleton might look like below:

begin tran
<TSQL statement for table 1>
if @@error != 0 goto error
<TSQL statement for table 2>
if @@error != 0 goto error
commit tran
goto ok
rollback tran
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

try using foreign key "on update cascade".

see if id's or by any other means primary key- foreign key constraint can be applied
Member 8090436 11-Mar-13 10:10am
Your provided approached helpful only while we need to change Parent column and want to update child column value when they have Primary-foreign key relationship.
But in my scenario assume both belongs to different tables and also different columns.
If you have idea suggest me one or two!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100