LibrarySites.Banner

28 Days of Sitecore Rocks: Query Analyzer

Of all the features in Sitecore Rocks I would say that the Query Analyzer is in the top three.  Due to the sheer power of the Query Analyzer, it's hard to write only a single blog article about it.  Therefore, this article will get you started using the Query Analyzer and provide a few resources to help along the way.

Let's start by opening the Query Analyzer.  Right click on a database, navigate under the Tools menu and select "Query Analyzer" from the menu.

 

Sitecore Rocks

 

If you've never worked with the Query Analyzer before, the best way to get familiar with what's available is to start with the help commands.  Simply enter "help" for the query and execute.  This will return the list of commands available at our disposal.

 

Sitecore Rocks

 

We can dive deeper in the commands help by appending a command to the help query.  For example, if you enter "help select" and execute this query you will see all the options and syntax for the select command.

 

Now that we have a basic idea what commands are available let's execute some queries and see the results.  If you are intimately familiar with the Sitecore Query syntax then you will most likely be able to jump right in and query away.  If not, there are a couple good resources to help get you familiar.  The first resource is the "Samples" button at the top of the Query Analyzer.  This will take you to the Sitecore Rocks wiki page for Sitecore Query Analyzer Samples.  The second great resource is John West's blog article titled "Sitecore Rocks Query Analyzer Ingredients for the Sitecore ASP.NET CMS."

 

Sitecore Rocks

 

After running a query in the Query Analyzer we have several options with the results.  If we open the context menu on a result item we can navigate to the item by selecting the "Locate in Sitecore Explorer" menu item.  We can also export the results of our query to HTML, XML, or CSV formats.

 

Sitecore Rocks

 

Want to return certain fields in your results?  No problem.  If you know the name of the field off the top of your head then you can write it out with an ampersand (@) in front to return just that field.  If you don't remember the exact name of the field, click the "Insert Fields" button at the top of the Query Analyzer and filter by Template.

 

Sitecore Rocks

 

The advantage of selecting specific fields is that you can edit the field’s content directly in the Query Analyzer results!  When you tab off of the field that you edited, the item is automatically saved.

 

Sitecore Rocks

 

Additioanlly, if you don't know the path for your query, you can use the "Insert Path" dialog to navigate the Sitecore tree and select the exact path needed.

 

Once you have worked with the Sitecore Rocks Query Analyzer you will find a vast number of usages and question how you ever worked without it.  I highly recommend every developer uses this tool and never look back!

 

More Sitecore Rocks features tomorrow, don’t miss out!
  • I have found the following query to be incredibly useful for understanding if a rendering/sublayout is in use or not, and if so, where:  select @@path from //*[contains(@__Renderings, '{CB1C1246-6032-4E89-B57D-7E430061CEC9}')]  Set the guid to the guid of the sublayout/layout/rendering The results will list all templates, content items, etc that use it.

  • Is Query Analyzer only available for local instances of Sitecore?  I don't have that entire section of options listed in the Tools menu when I connect to deployed instances.  I only receive the section containing Sites thru Validation, Recycle Bin, and Switch Language.  Any ideas?

  • Is Query Analyzer only available for local instances of Sitecore? I don't have that entire section of options listed in the Tools menu when I connect to deployed instances. I only receive the section containing Sites thru Validation, Recycle Bin, and Switch Language. Any ideas?  

  • Query Analyzer option is not coming under the right click option of tools ,database.

  • I also have this issue   Query Analyzer option is not coming under the right click option of tools ,database.