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 |
|
SQL_Rookie
Starting Member
32 Posts |
Posted - 2007-04-25 : 22:14:30
|
| ok I have a transaction that looks like this...its just in query analyzer for now...begin trandelete from tableAalter tableB drop FKdelete from tableBalter tableB add FKproblem I have is that the alter tableB statement to add the FK pukes cause the constraint is missing id's which is ok ....but if I go to ROLLBACK tran I get an error stating there was no transaction started...why is that...I have a begin tranin fact if I leave out that alter add statement and run the 2 deletes and alter drop fk ....I can rollback the tran....is that cause it didn't error out...and when it error out it rollback automatically?? |
|
|
mattyblah
Starting Member
49 Posts |
Posted - 2007-04-26 : 00:24:27
|
try this, put the following in a stored proc:create procedure usp_testprocasbegin trandelete from tableAif @@error <> 0beginrollback tranreturn -1endalter tableB drop FKif @@error <> 0beginrollback tranreturn -1enddelete from tableBif @@error <> 0beginrollback tranreturn -1endalter tableB add FKif @@error <> 0beginrollback tranreturn -1endcommit tran what happens when you run:exec usp_testproc |
 |
|
|
|
|
|