这个问题试图探讨SQL Server 2000中TransactionScope和xact_abort之间交互所涉及的语义。
如果在TransactionScope中执行了以下sql,并且第一个delete命令出错,那么第二个delete命令是否会运行? (假设从父母到子女的外键以确保失败。)
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;
}
}
如果存储过程中的第一个delete语句失败,那么此方法的返回值是多少?如果第二个删除语句失败怎么办?