Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 java and SQL

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-09-20 : 08:07:00
Homood writes "Hi every one:

I am working on a project with java language, the project sends SQL statements to be executed.
In the project I need to delete all old values of the user from the database then entering the new data, but there is a risk of doing this. For example if the connection failed after executing the delete statement and before the insert statement the user will end up with no data.

The question is how to make sure that the delete statement will be executed only and only if I have the insert statement that should be executing after it."

JimL
SQL Slinging Yak Ranger

1537 Posts

Posted - 2004-09-20 : 08:15:17
Begin Transaction

(your code here)


IF @@ERROR <> 0
BEGIN
ROLLBACK TRANSACTION
END

COMMIT TRANSACTION

Jim
Users <> Logic
Go to Top of Page
   

- Advertisement -