SQL Server Management Studio 2016 → Activity monitor → Show execution plan - sql-server

I have a problem when I want to see the execution plan of an expensive recent query. The problem is that the result is displayed in XML and not as a design over the execution plan.
Does anyone know how to fix this?

First of all, for me it works out of the box. Microsoft SQL Server Management Studio 13.0.15700.28. Make sure that you have the latest version. The one that I used for this test is not the very latest, but it works.
I open Activity Monitor in SSMS, expand the Recent Expensive Queries tab, right-click on a query and choose Show Execution Plan in the popup menu, then SSMS opens a new window with the graphical view of the plan.
If I right-click the graphical view of the plan there are commands "Save Execution Plan As..." and "Show Execution Plan XML" in the popup menu, which allow to save XML file with the plan.
Maybe all this works because I have SQL Sentry Plan Explorer installed.
In any case, if you have an XML file with the plan you can open it in SSMS as a graphical view. Change extension of the file from .xml to .sqlplan. Then open this file in SSMS using standard File - Open command.
I would highly recommend to use SentryOne Plan Explorer for analyzing the execution plans. It is free and significantly better than SSMS. It can open .xml and .sqlplan files with the plan.

I'm not sure if this will help but you could try execute SET SHOWPLAN_ALL OFF in a query window select the query you want to execute and press CTRL + L (by default, unless you've changed it) to view the graphical execution plan in the query window without actually executing your query.
Also, you could play around these SET commands:
SET SHOWPLAN_XML ON | OFF
SET SHOWPLAN_TEXT ON | OFF
SET SHOWPLAN_ALL ON | OFF
SET STATISTICS XML ON | OFF
SET STATISTICS PROFILE ON | OFF
SET STATISTICS IO ON | OFF
SET STATISTICS TIME ON | OFF
For further info, check this technet article: https://technet.microsoft.com/en-us/library/ms180765(v=sql.105).aspx

users must have the appropriate permissions to execute the Transact-SQL queries for which a graphical execution plan is being generated, and they must be granted the SHOWPLAN permission for all databases referenced by the query

Related

How do you re-run an already executed query from 'Query History' pgadmin?

As in pgAdmin 4 screenshot, one can see a list of recently executed queries.
The play button, Execute / Refresh(F5) tool executes the most recent query instead of the selected/highlighted one.
I know I can click on a query, and from the right side pane click on copy and go to the Query Editor to run it.
My question is, is there a shortcut or some options using GUI in pgAdmin 4 to re-run the query of my choice (selected/highlighted query) from history?
Unfortunately, you cannot execute this in View/Edit table mode. However, you can copy the SQL and open a new query tool, paste the query and run it.

How to view execution plans in SQL Server on Linux

I have SQL Server installed on Linux. It was installed from Microsoft's repos as described here:
https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-ubuntu
In MySql I used to write EXPLAIN in front of my query to see the execution plan. In SQL Server it doesn't seem to work. But I don't have the studio program installed, only just SQL Server and the sqlcmd tool.
How do I see the execution plan of a query in SQL Server on Linux?
Microsoft released a new tool called SQL Operations studio,this is similar to SSMS,but is available on Windows,Linux,Macos.
location for download:
https://learn.microsoft.com/en-us/sql/sql-operations-studio/download
Below is a screenshot of how it looks like
To view actual execution plan using sqlopsstudio(steps same for all platforms)
Press CTRL+SHIFT+P
Type run query with actual execution plan as shown below and select the highlighted, you will get an actual execution plan
To view estimated execution plan :
Just press the ICON shown below
You can also use a keybinding to view actual execution plan .Below are the steps
1.Press CTRL+SHIFT+P
2.Type keyboard shortcuts
3.In the search plan type actual as shown below
4.Right click actual query plan shortcut and say add key binding with a key of your choice(for me it is CTRL+M
Below Part of the answer was written during the time when SQLOPS studio is not available.This can ben helpfull for any one who don't have SQLopsstudio:
Currently viewing execution plan is supported only if you are on Windows,using SSMS or some third party tool like SQLSentry..
There is a feature request being tracked here :Return ShowPlan data as Text or XML with Query Execution
one more option is to connect using VSCODE on linux and set show plan xml as shown in screenshot below..this provides xml of execution plan
SET showplan_xml ON;
you can take that xml and upload it Paste The Plan website and can view plans
Below is a screenshot of above XML
you can also view it in SQLSENTRY plan explorer as well(Windows only) for more indepth analysis

TFS + MSSQL continuously loads 30% of CPU

I found that on my computer the CPU loaded on 30% all time. In the Task Manager I found that MSSQL loads the CPU. It was strange because as I know I didn`t use SQL at that time. I launched the SQL Server Profiler and found that all time used the Tfs_Configuration database.
It was strange because I didn`t use tfs at that time.
I launch the TFS Admin Console and stop the default collection (it is only one collection) + restart the SQL service. But it nothing changed.
So:
Why it happens? Why there are the Tfs_Configuration used all time?
How to stop it?
UPDATE
Configuration:
WinServer2012R2Standard
MS SQL Server 2016 RTM
TFS 2015 Update 3
TFS installed with defaults (one default collection, etc.)
No I don`t want stop TFS. I want understand why Tfs_Configuration used by MSSQL all time, even when I nothing to do and great loads CPU + I want to fix this issue.
So, I found the problem.
.
TFS will put a full text index into the satellite databases. It will set this full text index to 'auto' for change tracking. This will cause the server to continuously, on its own, to scan and rebuild the index, even when nothing is happening. This sql code will cause the index to stop rescanning.
use Tfs_<YOUR Collection>
go
exec sp_fulltext_database 'disable'
go
alter fulltext index on WorkItemLongTexts set change_tracking = OFF

keyboard shortcut to script as...CREATE TO...new query editor window

I've been handed some legacy SQL Server 2005 database, and we have it running on SQL Server 2008 R2. There's a lot of reference to entities through inline SQL and no foreign keys, so I find myself repeatedly opening the T-SQL source of stored procs, which means going through the "script stored procedure as...CREATE to...new query editor window" GUI menu. Is there a way to bind this to a keyboard command?
In SSMS go to Tools -> Options and then see the screenshot for Ctrl + F1
Basically I execute shortcut Ctrl + F1 in my case
Give this a shot
EXEC sp_helptext 'sp_name'
It will work for any "code" but not tables etc.

Is there a way to open a sql file in SQL Server Management Studio?

I have thousands of stored procedures in my data base. And I can't stand scrolling through the entire list to find the SPROC I'm looking for. Is there a command in sql server mgmt studio to open the file in the editor like 'OPEN dbo.SomeStoredProcedureName'
There is no T-SQL command to do this, as SSMS is just a client management tool. Your best bet is to use the Filter tool built in to SSMS:
I don't believe there is such command but if you just want to see and not update you could use
sp_helptext 'dbo.SomeStoredProcedureName'
This messes up the formatting so you shouldn't use it to update (while you can). I also map a key to it Ctrl-F1 that can be used to just write the name and select an d press Ctrl-F1.
You've got lots of options, depending on exactly what you're trying to do:
You can "open file" and graphically browse to the directory you want, then graphically scroll down to and open the file you want.
You can "use" the database you want, and "exec" the stored procedure you want from a command-line query window.
You can "exec sp_helptext XXX" the stored procedure to see the text in a command-line query window.
You can use "filter" in the GUI to eliminate stuff you don't want to see
You can write a VBScript or Powershell script to do the same stuff the SSMS GUI lets you do.
Etc etc
You could export the whole database to a creation script. Then it would be easy to search in your favorite file viewer.
From Management Studio you can right-click on the database, choose Tasks->Generate Scripts, and then select "Stored procedures". If you're just browsing, this is very handy. Also good to store such scripts in your code repository.
SqlSmash lets you navigate easily to any object (including stored procedures) in SSMS.
Source
Disclaimer: I am the developer for the addin.

Resources