TSQL logging inside transaction(事务中的 TSQL 日志记录)
问题描述
我正在尝试写入事务内的日志文件,以便即使事务回滚,日志也能保留下来.
I'm trying to write to a log file inside a transaction so that the log survives even if the transaction is rolled back.
--开始代码
开始翻译
将[东西]插入dbo.logtable
insert [something] into dbo.logtable
[[此处的主要代码]]
[[main code here]]
回滚
提交
-- 结束代码
你可以说只在事务开始之前做日志,但这并不容易,因为事务在这个 S-Proc 运行之前开始(即代码是更大事务的一部分)
You could say just do the log before the transaction starts but that is not as easy because the transaction starts before this S-Proc is run (i.e. the code is part of a bigger transaction)
所以,简而言之,有没有办法在不属于事务的事务中编写特殊语句.我希望我的问题有意义.
So, in short, is there a way to write a special statement inside a transaction that is not part of the transaction. I hope my question makes sense.
推荐答案
使用表变量 (@temp) 来保存日志信息.表变量在事务回滚后仍然存在.
Use a table variable (@temp) to hold the log info. Table variables survive a transaction rollback.
请参阅这篇文章.
这篇关于事务中的 TSQL 日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:事务中的 TSQL 日志记录
基础教程推荐
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 无法解决整理冲突 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
