TFS keeps track of an activity log of all recent activities. This information is stored in 2 tables inside Tfs_Configuration and Tfs_collectionname called tbl_Command and tbl_Parameter. These tables keep a record of every single command that every single user has executed against TFS for the last 14 days(!).
So if you want to know which query is used to execute a specific action, it’s not that hard to find it through the Activity log.
If you don’t like to open SQL Server Management studio, you can also browse to the ‘hidden’ management pages at http://<tfsurl/_oi
Note: You can only access these pages when you do it directly from your TFS application server
When you click on the … next to the command you can see the related details