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.
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.a1set 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 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
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 KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
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 KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
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 correctlyby looking at the the original posters sql statement, my opinion is that he lacks that. _______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
|
|
|
|