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 日志记录


- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- SQL 临时表问题 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01