Sql-server – Oracle dbms_xplan.Display() equivalent to SQL Server 2017

oraclesql-server-2017

I am converting some sql from Oracle to SQL Server 2017.

One of SQL code is having dbms_xplan.Display() inside the script.

I want to know what is the equivalent of dbms_xplan.Display() in SQL Server 2017.

Best Answer

SET STATISTICS XML ON;
GO
SELECT ... FROM ...;

This will produce a rowset with a clickable XML showplan:

enter image description here

Clicking on the XML will render a new tab with the graphical showplan. If you just want text output, instead of STATISTICS XML, use:

SET SHOWPLAN_TEXT ON;
GO
SELECT ... FROM ...;