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...
Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. data sciences
ReplyDeleteI’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... Allentown Web Design
ReplyDelete