Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai All,

I want to know which table got updated after doing a transaction from front end in MS SQL.

I checked the below code..
but didn't meeting my expectations.

I want the table in which data got inserted after doing a transaction.

please help me

What I have tried:

SELECT deqs.last_execution_time AS [Time], dest.TEXT AS [Query], dest.dbid
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
ORDER BY deqs.last_execution_time DESC
Posted
Updated 1-Mar-17 23:54pm

Hope this will help you.
This Solution will help for less tables

1.Create a Table with following columns

TableName : LastUpdateTableInfo

1.Id - primary key(Auto generate)
2.TableName
3.UpdateDate

2.Create the AfterUpdate Trigger for each tables

use [DatabaseName] 
Go
create trigger trgupdatetableInfo on [TableName]
for update
as
declare @tableName as varchar(50)
declare @lastUpdateTime as varchar(50)

set @tableName =[yourtablename]
set @lastUpdateTime= GETDATE()

insert into dbo.LastUpdateTableInfo (tablename,UpdateDate) values (@tableName,@lastUpdateTime)
Go


Now whenever update happens the mention table will log the info .

You can get the last update table name by supply the following Query
SELECT  [Id]
      ,[TableName]
      ,[UpdateDate]
  FROM [placeDB].[dbo].[LastUpdateTableInfo] order by Id desc
 
Share this answer
 
v2
 
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