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 日志记录
基础教程推荐
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 在多列上分布任意行 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
