Are ad-hoc read-only queries stored in SQL Server transaction log?

假装没事ソ 提交于 2019-12-12 11:45:36

问题


In SQL Server 2008 with the database recovery model configured to full, are queries such as

select col1,col2,col3 from TableName

logged to the transaction log files.

In other words, can I determine what queries were run on the database on a particular day using the transaction log backups?


回答1:


No. The transaction log does not record queries at all. It just records the info necessary to roll forward or roll back transactions (and a SELECT query would not generate any logged activity at all)

You can try

select top 100 *
from sys.fn_dblog(default,default)

to have a look at the kind of stuff recorded.

If you needed this kind of information you would need to set up a trace / extended events session / audit session to record it. This could be prohibitively heavy weight in most environments.

You could use the following to get a general idea about what adhoc queries are being run.

SELECT text 
from sys.dm_exec_cached_plans
cross apply sys.dm_exec_sql_text(plan_handle)
where objtype='Adhoc'


来源:https://stackoverflow.com/questions/5516358/are-ad-hoc-read-only-queries-stored-in-sql-server-transaction-log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!