Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update two tables simultaneously

Author  Topic 

Kurmanc
Yak Posting Veteran

92 Posts

Posted - 2009-04-28 : 08:01:18
Hi

Is tehre a way in SQL Server to update two tables simultaneously? I tried the following with no success. Any idea?


UPDATE t1, t2
SET
t1.productname= 'sony x3'
,t2.number = 5554
FROM table1 t1
INNER JOIN table2 t2
ON t1.id = t2.t1id
WHERE t1.name= 'sony'

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-04-28 : 08:14:58
No, you'll have to do:

UPDATE t1 SET Productname='sony x3'
FROM table1 t1
INNER JOIN table2 t2 ON t1.id = t2.t1id
WHERE t1.name= 'sony'

UPDATE t2 SET number=5554
FROM table1 t1
INNER JOIN table2 t2 ON t1.id = t2.t1id
WHERE t1.name= 'sony'

Go to Top of Page

Kurmanc
Yak Posting Veteran

92 Posts

Posted - 2009-04-28 : 08:17:45
robvolk

I was afraid so. Thanks anyway.
Go to Top of Page
   

- Advertisement -