SQL Server equivalent to MySQL’s EXPLAIN

The MySql EXPLAIN statement can be used either as a synonym for DESCRIBE or as a way to obtain information about how MySQL executes a SELECT statement.

The closest equivalent statement for SQL Server is:

SET SHOWPLAN_ALL (Transact-SQL)
or
SET SHOWPLAN_XML (Transact-SQL)

From a SQL Server Management Studio query window, you could run SET SHOWPLAN_ALL ON or SET SHOWPLAN_XML ON and then your query. At that point It will not return the result set of the query, but the actual execution plan. When you then run SET SHOWPLAN_ALL OFF or SET SHOWPLAN_XML OFF and then run your query, you will then again get a result set.

Leave a Comment