如何在sql中更新3个链接表
问题描述:
我有3张桌子T1,T2,T3
T1(t1id = pk,field1 ......)
T2(t2id = pk,field2,t1id = fk )
T3(t3id = pk,field3,t2id = fk)
I have 3 tables T1,T2,T3
T1(t1id=pk,field1...)
T2(t2id=pk,field2,t1id=fk)
T3(t3id=pk,field3,t2id=fk)
答
信息太少,几乎不可能给你正确的咨询。但是,以下信息可能对您有用...
了解SQL事务。一些链接 -
了解交易的初学者教程ADO.NET中的TransactionScope [ ^ ]
SQL Transactions [ ^ ]
和TRY-CATCH - 请参阅使用Try ... Catch ...,最后! [ ^ ]
eg
With so little information it is almost impossible to give you proper advice. However the following information may prove useful to you...
Learn about SQL Transactions. Some links -
A Beginner's Tutorial for Understanding Transactions and TransactionScope in ADO.NET[^]
SQL Transactions[^]
and TRY-CATCH - see Using Try... Catch..., Finally![^]
e.g.
BEGIN TRY
BEGIN TRANSACTION
-- update table T1
-- update table T2
-- update table T3
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
END CATCH
要么所有三个表都会成功更新,要么都不会更新。
您必须更新3个链接表的事实可能意味着您没有规范化您的数据库充分 - 看看规范化基础知识 [ ^ ]