/ Published in: SQL
To know who are the users logged in to sql server in te past previous days.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
SELECT DB_NAME(database_id), LastRead = MAX(CASE WHEN last_user_seek > last_user_scan AND last_user_seek > last_user_lookup THEN last_user_seek WHEN last_user_scan > last_user_seek AND last_user_scan > last_user_lookup THEN last_user_scan ELSE last_user_lookup END ), LastWrite = MAX(last_user_update) FROM ( SELECT database_id, last_user_seek = COALESCE(last_user_seek, '19000101'), last_user_scan = COALESCE(last_user_scan, '19000101'), last_user_lookup = COALESCE(last_user_lookup, '19000101'), last_user_update = COALESCE(last_user_update, '19000101') FROM sys.dm_db_index_usage_stats ) x GROUP BY DB_NAME(database_id) ORDER BY 1;