Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Administration - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 6525

List of Users that Accessed a Table

$
0
0
I'm trying to find out what tables are being used in a Database.I don't want the last User but the User and the Dates.I have a script that return the last user but that is not going to work.Any input would be greatly appreciated.Thanks.The following script returns the last user but not all users and the Login Name:[code="sql"]ITH LastActivity (ObjectID, LastAction) AS ( SELECT object_id AS TableName, last_user_seek as LastAction FROM sys.dm_db_index_usage_stats u WHERE database_id = db_id(db_name()) UNION SELECT object_id AS TableName, last_user_scan as LastAction FROM sys.dm_db_index_usage_stats u WHERE database_id = db_id(db_name()) UNION SELECT object_id AS TableName, last_user_lookup as LastAction FROM sys.dm_db_index_usage_stats u WHERE database_id = db_id(db_name()) ) SELECT OBJECT_NAME(so.object_id) AS TableName, MAX(la.LastAction) as LastSelect FROM sys.objects so LEFT JOIN LastActivity la on so.object_id = la.ObjectID WHERE so.type = 'U' AND so.object_id > 100GROUP BY OBJECT_NAME(so.object_id)ORDER BY OBJECT_NAME(so.object_id)[/code]

Viewing all articles
Browse latest Browse all 6525

Trending Articles