Sunday, August 18, 2019

Get Executed SQLs From Database

Get Executed SQLs From Database

If you need to get executed SQL statements from database, then you can used this method to read it,

First we will insert one record,

INSERT INTO [DATABASEUSERGROUP].[dbo].[XX](col2)SELECT 2015GO 

Next you can read it as follows,

SELECT qs.last_execution_time, st.[TEXT] AS [SQLQuery]FROM sys.dm_exec_query_stats AS qsCROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS stWHERE (lower(st.[TEXT]) like '%insert%')AND (lower(st.[TEXT]) like '%xx%')AND (lower(st.[TEXT]) like '%col2%')ORDER BY qs.last_execution_time DESC



I'm not mistaken if you restart MSSQL Server service then this record will be deleted! I didn't try it just add comment after try it...

Cheers...
and Most welcome your comments and ideas...

No comments:

Post a Comment