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 2000 Forums
 SQL Server Development (2000)
 Multiple table update

Author  Topic 

sql_2k
Starting Member

26 Posts

Posted - 2008-04-07 : 14:41:52
Hi All, Please let me know how to update the field values in mutiple related table. For Ex -


create table tbl1( a1 int, b1 int)
create table tbl2( a2 int, b2 int, a1 int)

insert into tbl1 values(1, 10)
insert into tbl2 values(1, 22,1)
insert into tbl2 values(2, 11, 1)



update tb1 join tb2 on tb1.a1 = tb2.a1
set b1 = 99, b2= 88

the above update query throws syntax error, plz advise.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-04-07 : 14:48:12
http://weblogs.sqlteam.com/mladenp/archive/2007/08/19/60292.aspx

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-07 : 14:49:10
You can't update both tables at the same time. You'll need two statements.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-07 : 14:55:40
Mladen, how does your blog apply to his problem? If he's just using scalar values in the SET part, then a join shouldn't be used. Plus he wants to update both tables in one query, which isn't possible.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-04-07 : 15:18:21
it applies to general understanding of how DML works when used for more than one table.
It has to be first understood to be applied correctly
by looking at the the original posters sql statement, my opinion is that he lacks that.




_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page
   

- Advertisement -