gpt4 book ai didi

sql-server - 触发器是否作为 SQL Server 中事务的一部分出现

转载 作者:搜寻专家 更新时间:2023-10-30 20:47:43 26 4
gpt4 key购买 nike

我在 SQL Server 中有三个表:

  1. 员工
  2. 员工详情
  3. 员工历史

我在 Employee 表上写了一个触发器,这样如果条目被插入到 Employee 中,那么它也会在 EmployeeHistory 中插入一行;工作正常。

现在我已经创建了带有事务的存储过程,并将记录插入到 Employee,然后是 EmployeeDetails。插入记录到Employee后,如果有任何问题,事务被回滚,那么插入到EmployeeHistory中的行是否也被删除?

最佳答案

默认情况下,选项 XACT_ABORT 在触发器中为 ON It can be seen here .当此功能ON 时,发生的任何错误都会中断/中止批处理,因此您的整个事务将被回滚。

Microsoft documentation says :

When SET XACT_ABORT is ON, if a Transact-SQL statement raises a run-time error, the entire transaction is terminated and rolled back.

When SET XACT_ABORT is OFF, in some cases only the Transact-SQL statement that raised the error is rolled back and the transaction continues processing. Depending upon the severity of the error, the entire transaction may be rolled back even when SET XACT_ABORT is OFF.

关于sql-server - 触发器是否作为 SQL Server 中事务的一部分出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53349469/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com