Hi all, I was wondering is there any t-sql query to figure out the last login to have accessed a database. I have a few databases that no one knows what or who is accessing them. It says the date last used is today because I run backups everyday. I am trying to figure out if there are any applications using this database. Thanks.
The best way to do this would be to use extended events to capture logins so that you know precisely who is connecting to what. You can also add extended events to capture what queries they're running. But, you have to have it set up in order to capture this. Nothing built-in to the system automatically captures this type of information. However, you do have the option of looking at the cache to see what queries have been run, but not who ran them. You can look at sys.dm_exec_query_stats to see an aggregate of attributes about queries that are currently in cache. This won't do what you need, but it's an additional investigative tool you can use until you get the extended events set up.