Listing Updated Tables in SQL Server
In this article, I will talk about how to list updated tables in SQL Server.
In SQL Server, in some cases, it may be desirable to know which tables have been updated.
I will describe my transactions using the Northwind database.
Let’s check if there is a change on the related database using the following query.
SELECT tbl.name, ius.last_user_update, ius.user_updates, ius.last_user_seek, ius.last_user_scan, ius.last_user_lookup, ius.user_seeks, ius.user_scans, ius.user_lookups FROM sys.dm_db_index_usage_stats ius INNER JOIN sys.tables tbl ON (tbl.object_id = ius.object_id) WHERE ius.database_id = DB_ID();
When we call the query before making changes to any table, you will get a result like the one below.
As you can see, it came up empty because we didn’t make any changes (Insert, Update, Delete) in the database before.
Now, let’s make the CategoryName name Deniz Ürünleri for the category with CategoryID=8 in the Categories table.
UPDATE dbo.Categories SET CategoryName = 'Deniz Ürünleri' WHERE CategoryID = 8;
Let’s run the query.
As you can see we have updated it. Now let’s check with the first query we wrote.
As you can see, it showed us that there was an update in the Categories table.
Good luck to everyone in business and life.