Thursday, October 9, 2008

How do you use the Query Designer in SQL Server 2008?

Well, there are a few steps you need to follow. This note shows how you may create and execute a query in the SQL Server Management Studio. I am using a copy of the Northwind database.

Step 1:

Click on New Query toolbar item [directly below File in SQL Server Management Studio]

Step 2:

In the new empty query created [herein SQLQuery1.sql - Hodentek2\...]. Right click on an empty area and choose Design Query in Editor





















Query Designer pops-up with the Add Table modal window on top of it as shown.























Step 3:

Hold down Control Key and highlight Products and Suppliers in the Add table list and click on the Add button. After the tables are added close the window.

The Tables get added to the Query Designer together with the relationship between them as shown.











Step 4:

Place check marks for the columns in Products and Suppliers as shown.
You do not need to do anything with the Grid Pane or the SQL Pane below it. Just observe them as you place the check marks.















Step 5:

Execute the query in the designer and if you are satisfied click OK.
The SQL Statement gets in to the Query window.
Study the SQL Statement.

You are done!!
You successfully used the Query Editor to query two tables in the database.

7 comments:

Unknown said...

Thank you for the clear and concise example!

tObz lerOne said...

thank you ...

Novo Sonica said...

Thank you! It's down to web posts from you like this that help save me and others from massive stress every day - in an ideal world I would get chance to have lots of training (I would even pay for it myself too!) but in this current economy both my wallet and that of my employer is full of dust, so I make do with what I can & am quite grateful that the Internet still works in the UK!

zhollett said...

only one problem... You cannot execute the query from within the query designer. How did you get around this?

Debbie said...

Thanks for this, just what I needed to know today!

FAO person that commented above - to execute the query, once you have the criteria you want in the window, click ok, then the SQL for your criteria will appear in the pane below, you can then execute that.

To make a change, then highlight the SQL, right click and select 'Design Query in Editor' and repeat.

Debbie said...

Thanks for this, just what I needed to know today!

FAO person that commented above - to execute the query, once you have the criteria you want in the window, click ok, then the SQL for your criteria will appear in the pane below, you can then execute that.

To make a change, then highlight the SQL, right click and select 'Design Query in Editor' and repeat.

Unknown said...

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