Possible Duplicate:
How to update two tables in one statement in SQL Server 2005?如何更新單查詢兩個表中的SQL Server 2008
我有兩個表,並需要更新一個表並生效的其他表。
這兩個表通過關係
t1.col1 PK , t2.col1 FK
t1 t2
_____________ _____________
|col1| col2| |col1 |col2 |
|----|------| |-----|-----|
|1 | a | | 1 | d |
|2 | b | | 2 | e |
|3 | c | | 3 | f |
|____|______| |_____|_____|
我如何更新在SQL Server 2008中一個查詢這兩個表的鏈接?
我想要做這樣的事情
Update College
Inner Join Class ON College.CollegeId = Class.CollegeId
set College.CollegeId = '33333333-3333-3333-3333-333333333333',
Class.CollegeId = '33333333-3333-3333-3333-333333333333'
where
College.CollegeId = '071887ea-3c93-40ce-a112-3b849d352064'
,但我得到一個錯誤:
incorrect syntax near the keyword "Inner"
爲什麼不直接在事務中創建兩個更新語句? – rikitikitik
與@AlanKuras同意。還有在2008年和2005年SQL在這個問題上沒有什麼區別 –
開始交易,UDPATE表1,表2更新,提交。更簡單,更mantainable,不容易出錯 – Alex