Forum Moderators: open

Message Too Old, No Replies

How to Update more than 1 table?

updating multiple tables

         

nuckz

2:27 pm on Oct 4, 2006 (gmt 0)

10+ Year Member



Hi there,

I'm using MS SQL Server 2000, and I need to update one collumn in one table, and another column in another table, something like this:

UPDATE table1,table2
SET table1.col1 = '1', table2.col2 = '2'

how can I do it?

thank you for your attention.

syber

4:20 pm on Oct 6, 2006 (gmt 0)

10+ Year Member



You must create two seperate update statements. It's a good idea to make them a part of an explicit transaction so that you are sure both tables were updated.

BEGIN TRANSACTION

UPDATE table1
SET col1 = '1'

UPDATE Table2
SET col2 = '2'

COMMIT TRANSACTION