Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
sir,
how to update two table data in single query using sql server 2005
Posted

You achieve like this:
you can use a transaction two make sure that two UPDATE statements are treated correct.
SQL
BEGIN TRANSACTION

UPDATE FirstTable
  SET FirstTable.col1= 'XXXX' 
FROM FirstTable T1, SecondTable T2
WHERE T1.id = T2.id
and T1.id = '010008'

UPDATE SecondTable
SET SecondTable.col1 = 'XXXX'
FROM FirstTable T1, SecondTable T2
WHERE T1.id = T2.id
and T1.id = '010008'
COMMIT
 
Share this answer
 
v2
At a time, you can update data of a single table.
visit
http://stackoverflow.com/questions/3707815/update-multiple-tables-in-a-single-update-statement-with-left-join[^]

Happy Coding!
:)
 
Share this answer
 
HI,

Try like this.

SQL
UPDATE Table1, Table2
SET Table1.LastName = 'DR. XXXXXX'
,Table2.WAprrs = 'start,stop'
FROM Table1 T1, Table2 T2
WHERE T1.id = T2.id
and T1.id = '010008'


Thanks
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900