HI I AM STUCK WITH THE PROBLEM
CAN ANYONE HELP ME TO FIGURE OUT THIS
CAN WE UPDATE DATA INTO MULTIPLE TABLES AT THE SAME TIME
CAN WE DO THIS USING STORED PROCEDURE OR TRANSACTION OR IN ANY OTHER WAYS
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pravin MorePosted Nov 25, 2011, 2:38 AM
Hi Thiru,
you cannot update 2 tables in 1 SQL statement. You can write a stored
procedure to update both tables. And have the 2 UPDATEs wrapped within a
transaction.
SQL Server ex.:
BEGIN TRANSACTION
UPDATE table1
SET col1 = @values1
WHERE...
IF @@error <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR("Unable to update table1", 16, 1)
RETURN
END
UPDATE table2
SET col2 = @values2
WHERE...
IF @@error <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR("Unable to update table2", 16, 1)
RETURN
END
COMMIT TRANSACTION
Thanx,
Pravin.
Pravin MorePosted Nov 25, 2011, 5:34 AM
if my post help you then please mark it as correct answer.
Thanks,
Pravin.
thiru prakashPosted Nov 25, 2011, 5:20 AM
ThnQ for the reply