0

I use Microsoft SQL Server to maintain the data which received from other software (Smartplant Instrumentation). I want to know the last table which was updated and inserted by the data from the other software.

I used this query, but I didn't get the correct updated tables:

SELECT
    SCHEMA_NAME(9),
    name AS table_name,
    create_date,
    modify_date
FROM
    sys.tables
WHERE
    modify_date > DATEADD(DAY, -30, CURRENT_TIMESTAMP)
ORDER BY
    modify_date DESC;

2 Answers 2

0

The query you ran only tracks changes to metadata, not the actual values. You might want to to look at sys.dm_db_index_usage_stats, it could display the data changes in your tables:

select *
from sys.dm_db_index_usage_stats
where object_id = OBJECT_ID('your-table-name')

But the best way is to add a modify date to the tables you're monitoring, or implement Change Tracking or similar.

Sign up to request clarification or add additional context in comments.

Comments

-2
select top 10 name,modify_date 
from sys.tables 
where modify_date=(select max(modify_Date) from sys.tables) 

this will return top to 10 tables recently updated tables

2 Comments

This is completely wrong. This will return top 10 tables that are all modified at the exact same time, which is the most recent change to any table.
This is a corruption of what the user already tried, and does not answer the question. The user is attempting to determine when data in a table was modified. You might vote to delete to prevent more down votes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.