Learn more about SQL Server tools

   
   






















































Connect with MSSQLTips




MSSQLTips Facebook Page MSSQLTips LinkedIn Page MSSQLTips RSS Feed MSSQLTips Pinterest Page MSSQLTips Twitter Page MSSQLTips Google+ Page

SQL Server Management Studio Query Designer

MSSQLTips author Jeremy Kadlec By:   |   Read Comments (12)   |   Related Tips: More > Tools
Problem

When writing SQL Server queries I either need to reference an existing data model or visualize the SQL Sever tables from my database in my head in order to complete my query.  Does a visual query tool exist in the SQL Server Management Studio tool set?  If so, how can I access it and use it to streamline my SQL Server development process?  Check out this tip to learn more.

Solution

The SQL Server Management Studio ships with Query Designer which in a nutshell is a visual querying tool to build SELECT statements.  This is an add-in to the Query Window offering a means to add specific tables from a specific database to the designer.  You can see a visual representation of the tables with the referential integrity all in one screen, then build the needed query with JOINs, WHERE and\or ORDER BY clauses.

How do I access the SQL Server Management Studio Query Designer?

  1. Open SQL Server Management Studio.
  2. Select the database you want to query from in the drop down list of the SQL Editor tool bar, in our case 'BaltSSUG'.
  3. Navigate to the Query menu and select the 'Design Query in Editor...' option.  Alternatively, press Ctrl+Shift+Q.
  4. The Query Designer will load and follow the steps in next section to select the needed tables, then build and test the query.

What are the capabilities with the SQL Server Management Studio Query Designer?

  1. Select the user defined tables needed for the query.  System tables are not available as options in this tool.

SQL Server Management Studio Query Designer Table Selection

  1. Once the tables load in the top of the interface, arrange the tables so they make sense to you.  Next, select the columns that you want to use in the query as well as the alias, sort type, sort order, etc.  Notice how the T-SQL for the SELECT statement is being created and updated as columns are chosen.  Finally, press the 'OK' button and the query will then load into the original query window in SQL Server Management Studio as show in step 3.

SQL Server Management Studio Query Designer organized with tables to build a query

  1. The query as setup in step 2 will load into the original Query Editor window where the query can be executed, tested and modified to meet your needs.

Code from the SQL Server Query Designer is loaded into a SQL Server Management Studio query window for further development and testing

Can this tool help me with INSERT, UPDATE or DELETE statements?

Yes - as a matter of fact.  Just right click in the query pane and select Change Type and then the type of query desired.

SQL Server Management Studio Query Designer Supports SELECT, INSERT, UPDATE and DELETE commands

Next Steps


Last Update: 1/23/2013


About the author
MSSQLTips author Jeremy Kadlec
Jeremy Kadlec is the CTO @ Edgewood Solutions, co-founder of MSSQLTips.com, Baltimore SSUG co-leader and SQL Server MVP since 2009.

View all my tips
Related Resources


print tip Print  
Become a paid author





join MSSQLTips for free SQL Server tips     



Learn more about SQL Server tools
Post a comment or let the author know this tip helped you.

       All comments are reviewed, so stay on subject or we may delete your comment.

*Name   *Email Notify for updates



       Note: your email address is not published. Required fields are marked with an asterisk (*)


Get free SQL tips:

*Enter Code refresh code     



Thursday, July 03, 2014 - 10:40:59 AM - Megan Brooks Read The Tip

I have used the query designer extensively in the past, and it works with a number of different types of queries and with CTEs, "derived tables" and other T-SQL features (though not optimally) if you are using a recent version. I have recently started a new job, however, where the performance demands on the databases are much higher, and I have not opened the query designer once. The main issues are:

  • The resultant code can be weirdly arranged, and hard to fix (it may even re-arrange things back where they were before you fixed it)
  • It sometimes "optimizes" queries to the point of breaking them. Not all of the rearrangements that it applies are valid.
  • It's not useful for complex queries containing embedded comments that you want to keep.
It is still potentially a useful tool for diagramming complex queries, although I find that with practice I really don't need it for that, day to day. The key to using it with derived tables is to select just the derived table query itself and open the query designer against that. You can likewise open it against the query contained in a CTE -- it works against any selection that is a valid T-SQL query (among those CRUD query types that it supports but not, for example, MERGE).

Wednesday, June 05, 2013 - 7:23:21 AM - Royce Roy Read The Tip

This is awesome!! really helpful for me. Thanks for sharing with us. Following links also helped me to complete my task. 

 

http://technet.microsoft.com/en-us/library/ms177264.aspx

 

http://www.mindstick.com/Articles/f0aaa8d8-98be-48c1-b702-c5264b9e0213/?Design%20Query%20in%20Editor%20SQL%20Server%202008%20R2

 

Friday, May 24, 2013 - 11:16:28 AM - Ralph Wilson Read The Tip

This works great for a straight forward SELECT query but it won't work if you have any even mildly advanced features.  For instance, forget about using it with any of the following:

  • CTEs;
  • EXCEPT
  • LEFT OUTER JOIN to a subselect statement
  • IF {NOT} EXISTS . . .

Interestingly enough, it DOES work with an INSERT statement that selects from a CTE . . . as long as you don't try to include the CTE in what you are working with in the Designer area.  Of course, that is only marginally useful.


Monday, April 08, 2013 - 10:17:54 AM - Jeremy Kadlec Read The Tip

Susan,

No - Not that I am aware of.

Thank you,
Jeremy Kadlec
Community Co-Leader


Saturday, April 06, 2013 - 7:38:42 PM - Susan R. Read The Tip

Is there a way to have the "design query" GUI... and the "results" in 2 panes... but in the same 1 window?

 

I have to forever keep closing down the "design query" window... and moving back to the "sql view" and "results" windows separately.

 


Monday, February 11, 2013 - 9:04:58 AM - Scott Coleman Read The Tip

There used to be a "Design Query in Editor..." button on the toolbar in Enterprise Manager and possibly Management Studio 2005, but it is missing in SSMS 2008 and 2012.  The functionality is still there, and you can right-click on the Management Studio tool bar and choose "Customize" if you want to restore it.

You can also select the text of a query before starting the query designer, and it will open with that query as a starting point (assuming it was syntactically correct).  If you know which tables you're looking for in a large database, starting with "SELECT * FROM tablea,tableb,tablec" and then adding the joins in the query designer is easier than picking them from a very long dropdown list.


Monday, February 04, 2013 - 10:47:25 AM - Jeremy Kadlec Read The Tip

Sarmad,

I think all of the object references are to a single database.

Thank you,
Jeremy Kadlec
Community Co-Leader


Monday, February 04, 2013 - 5:41:11 AM - Sarmad Read The Tip

Hi,

Is Query Designer helpful in case we have multiple databases? e.g. database1..Table1 and database2..Table2? Thanks


Wednesday, January 23, 2013 - 2:01:59 PM - Jeremy Kadlec Read The Tip

Everyone,

This tip has been updated based on feedback from the community.

Thank you,
Jeremy Kadlec
Community Co-Leader


Wednesday, January 23, 2013 - 11:37:14 AM - Jeremy Kadlec Read The Tip

Krumeg,

No - Nothing that I am aware of with this tool.  Sorry.

Thank you,
Jeremy Kadlec
Community Co-Leader


Tuesday, January 22, 2013 - 1:04:26 PM - Krumeg Read The Tip

Hi Jeremy,

what if the database consists of a couple of hundred tables but to build your query you just need less than 10 tables. Can you somehow filter the list of tables you can use in the graphical query designer to display only those tables needed?

 

Thanks

Krumeg


Wednesday, August 11, 2010 - 4:57:15 PM - Gary Flatness Read The Tip
Jeremy,

I'm a novice at best on SQL (trial by fire), but found your article to be very helpful with my initial question. 

I saved the query, but when I close the program and reopen (and reopen the query) and execute, it gives an error message (message 208-invalid object name 'table name').  Do I need to rebuild the query each time the program is cycled, or is there something I can do to get it to execute without rebuilding each time.

Thanks and have a good day,

gflat




 
Sponsor Information