Click here to Skip to main content
15,887,965 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have 3 tables T1,T2,T3
T1(t1id=pk,field1...)
T2(t2id=pk,field2,t1id=fk)
T3(t3id=pk,field3,t2id=fk)
Posted
Comments
Kornfeld Eliyahu Peter 30-Jan-16 13:23pm    
And the question is?
You must be much more specific/detailed so we can help you...
John C Rayan 30-Jan-16 14:53pm    
what are you updating? Give some info.
Dave Kreskowiak 30-Jan-16 16:16pm    
Without more information, the short answer is "update one at a time".

1 solution

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

Either all three tables will be successfully updated or none of them will.

The fact that you are having to update 3 linked tables may mean that you haven't normalised your database sufficiently - have a look at Basics of Normalization[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900