Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii ,


I want to keep track on wther there are any unnecessary queriys running or not by some other user ..

How can i track the records ? please suggest me .. third party tools are not required .. want to check using some queriys only ./.

i tried somthing like this ..

SQL
SELECT t.[text]
FROM sys.dm_exec_cached_plans AS p
CROSS APPLY sys.dm_exec_sql_text(p.plan_handle) AS t
WHERE t.[text] LIKE N'%Insert into EndYearEmpCalibrationHeading%';





but this is session wise ... i want to check even if session ended ...


The thing have got on internet is the one as follow which give me query but not all the other details

SQL
SELECT execquery.last_execution_time AS [Date Time], execsql.text AS [Script] FROM sys.dm_exec_query_stats AS execquery
CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql
ORDER BY execquery.last_execution_time DESC



The other i have fond is gives me all the details but not query text ...c an anybody atlest help me to merge the both the things in one ..

SQL
SELECT
    ISNULL( SCHEMA_NAME([schema_id]) + '.','') + ISNULL(OBJECT_NAME(parent_object_id),DBLA.AllocUnitName) AS TableName ,

      DBL.[Begin Time] AS ModificationTime,
      COUNT(*) Total_Rows_Affected,
      MAX(DBL.[Transaction Name]) AS ModificationType,
MAX(SUSER_SNAME(DBL.[Transaction SID])) ModifiedBy

FROM Sys.fn_dblog(NULL,NULL) DBL
INNER JOIN Sys.fn_dblog(NULL,NULL) DBLA
ON  LEFT(DBL.[Current LSN],17) = LEFT(DBLA.[Current LSN],17) LEFT JOIN sys.key_constraints C
ON  SCHEMA_NAME([schema_id]) + '.' + OBJECT_NAME(parent_object_id) + '.' + C.name = DBLA.AllocUnitName

WHERE DBL.[Transaction Name] + '_' + DBLA.Operation IN ('INSERT_LOP_INSERT_ROWS',
'UPDATE_LOP_MODIFY_ROW',
'DELETE_LOP_DELETE_ROWS')

GROUP BY
ISNULL( SCHEMA_NAME([schema_id]) + '.','') + ISNULL(OBJECT_NAME(parent_object_id),
DBLA.AllocUnitName),DBL.[Begin Time]



I want both the results in one ...
Posted
Updated 18-Jun-14 0:44am
v4
Comments
Vedat Ozan Oner 18-Jun-14 6:48am    
Activity monitor may help: http://technet.microsoft.com/en-us/library/ms191199%28v=sql.105%29.aspx
Torakami 18-Jun-14 6:52am    
We are not admins .. so cant track all the changes with this utility
Torakami 18-Jun-14 6:53am    
Suggest me something for my above query ... can it be possible to merge both the things ... the problem is out log file is in shrink format.. we dont want to c much records but atlest monthly record will do ..

1 solution

Create an Execution Log table in the database, and in each script have an insert into this table. Insert one record as the very first statement in the script, and update this record in the very last statement of the script.
Record the time it was started, time finished, success/failure, name of script, account run under, etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900