Share via

last five update statement on table or view

Shambhu Rai 1,411 Reputation points
2023-06-13T16:03:03.8466667+00:00

Hi Expert,

how to get last five update statement fired on table or view in sql server

update table1 set col1=

update table1 set col2=

update table1 set col3=

Azure SQL Database
SQL Server Analysis Services
SQL Server Analysis Services

A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.

SQL Server | Other
{count} votes

4 answers

Sort by: Most helpful
  1. Sedat SALMAN 14,285 Reputation points MVP Volunteer Moderator
    2023-06-13T23:10:37.4366667+00:00

    i modified the query that Oury has shared with you (assuming you have configured auditing on SQL server)

    maybe this works for you

    USE master;
    
    SELECT deqs.last_execution_time AS [Time],
           dest.TEXT                AS [Query]
    FROM   sys.dm_exec_query_stats AS deqs
           CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
    WHERE  dest.text LIKE '%UPDATE%your_table_name%'
    ORDER  BY deqs.last_execution_time DESC
    
    

    the reference document for your question is as follows

    https://dba.stackexchange.com/questions/36149/how-to-find-delete-and-update-statements-that-have-been-executed-on-a-database

    1 person found this answer helpful.
    0 comments No comments

  2. Erland Sommarskog 133K Reputation points MVP Volunteer Moderator
    2023-06-13T21:59:45.27+00:00

    To get this information accurately, you need to set up the appropriate auditing. There is nothing built-in for this. The query that Oury shared gives some information, but is not accurate.

    1 person found this answer helpful.
    0 comments No comments

  3. Olaf Helper 47,616 Reputation points
    2023-06-14T05:08:40.81+00:00

    how to get last five update statement fired on table or view in sql server

    If you haven't implemented an auditing, then you can not get the informations.

    0 comments No comments

  4. Shambhu Rai 1,411 Reputation points
    2023-06-13T17:52:59.8833333+00:00

    any other suggestion please


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.