Click here to Skip to main content
15,895,815 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a table name clienttest in that i want to insert some data using storedprocedure from antoher data.The data has a forloop.now how can write a transcation query that if any error is there in the data then dont insert the data into the table else data should be inserted and commited.please help in this regard
Posted

SQL
BEGIN TRANSACTION myTrans
...
COMMIT TRANSACTION myTrans
 
Share this answer
 
Sample:
SQL
-- SP
BEGIN TRAN
    UPDATE Authors
    SET Phone = '415 354-9866'
    WHERE au_id = '724-80-9391'

    SELECT * FROM Authors

    UPDATE Publishers
    SET city = 'Calcutta', country = 'India'
    WHERE pub_id = '9999'
COMMIT TRAN

Here:
MSDN: BEGIN TRANSACTION (Transact-SQL)[^]
SQL Server Transactions and Error Handling[^]
 
Share this answer
 
v2

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