この質問は、SQL Server 2000 での TransactionScope と xact_abort の間の相互作用に関連するセマンティクスを調査する試みです。
次の SQL が TransactionScope 内で実行され、最初の削除コマンドがエラーになった場合、2 番目の削除コマンドが実行されますか? (失敗を確実にするために、親から子への外部キーを想定します。)
create procedure test
@id int
as
set xact_abort on
-- no explicit transaction is created
-- if this fails
delete from dbo.[parentTable]
where id = @id
-- will this run?
delete from dbo.[childTable]
where id = @id
以下のような単純なアプリケーション コードを想定します。
public bool TryTestStoredProcedure()
{
try
{
using (TransactionScope t = new TransactionScope())
{
MethodThatRunsTestStoredProcedure();
t.Complete();
return true;
}
}
catch
{
return false;
}
}
ストアド プロシージャの最初の削除ステートメントが失敗した場合、このメソッドからの戻り値は何になりますか? 2 番目の delete ステートメントが失敗した場合はどうなりますか?