事务中的 TSQL 日志记录 [英] TSQL logging inside transaction

查看:35
本文介绍了事务中的 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 日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆