I'm trying to establish some metrics associated with which tables in our database get joined together the most often. How can I go about accomplishing this?
edit: I should explain my reasoning; we are moving to a microservices-based architecture, and I would like to have join data in order to best inform the domain-driven-design.
Seeing which tables need to be joined most often would allow me to design certain data layer microservices in a way that they will always have access to easy joins of the most frequently-joined tables.
So if Table1 and Table2 are ALWAYS being joined, I can assess this and have them controlled by the same service. If not, I'll have different services control them.
Best Answer
I don't know if you can differentiate joins vs straight queries, but you can use index activity (what version of SQL Server, by the way?) to get an idea of your "hot" tables. This query should get you started, I use it to identify heavily fragmented or heavily used indexes, but it should still get you there. I don't think it will work with heaps that well, but you really shouldn't have many of those (or any) without a good reason.
I've written this mostly myself but of course cribbed and borrowed bits and pieces from others work. My thanks go out to everyone who has ever posted code to the internet.