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.
| Author |
Topic |
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2010-02-03 : 10:21:11
|
| I used code below to delete data in two tables.Question: What will happen if step 1 is ok but step 2 failed?Is one record deleted from employees table?-- STEP 1 BEGIN TRANSACTION DELETE FROM employees WHERE departmentid = @DepartmentID IF @@ERROR <> 0 BEGIN ROLLBACK RAISERROR ('Error in deleting employees',16,1) RETURN END ---- STEP 2 DELETE FROM departments WHERE departmentid = @DepartmentID IF @@ERROR <> 0 BEGIN ROLLBACK RAISERROR ('Error in deleting department',16,1) RETURN END -- STEP 3 COMMIT |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-02-03 : 10:32:10
|
| both rolled back |
 |
|
|
|
|
|