I have used MySQL for a long time and have found the general query log and the slow query log to be very useful in finding out what is happening on the server, and in identifying bottlenecks.
Now I need to use SQL Server. Does SQL Server have similar log facilities? If so, what are they called?
SQL server keeps statistical information about all queries in various tables. You can use the following code to determine what the longest running query is (from the
sys.dm_exec_query_stats
table).You should run the following DBCC commands:
This DBCC command clears the server cache and restarts logging of the query running time:
Run this query to find the longest running query:
You should also take a look at the Technet magazine article Optimizing SQL Server Query Performance, which has a query for determining which query is the most expensive read I/O query, as well as guidance on how to look at execution plans and other optimizations.
You can use SQL Profiler to monitor the system in real time to identify slow running statements.
SQL can also suggest indexes you might like to add or elimitate: http://msdn.microsoft.com/en-us/library/ms187974.aspx
You can also see reports in SQL Management studio related to long queries: Right-click your servername > reports > standard reports > Performance - Top Queries by...
Old slow queries are saved in MSSQL. This was already solved here:
http://blog.brianhartsock.com/2008/12/16/quick-and-dirty-sql-server-slow-query-log/