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.