Take the 2-minute tour ×

This should be a relatively simple thing to do. Basically I have SQL Server 2008, and I have attached NorthWind database to it. This is my query which works fine.

SELECT [Customers].[CompanyName], [Orders].[OrderID]
FROM [Northwind].[dbo].[Customers]
LEFT JOIN [Northwind].[dbo].[Orders]
ON Orders.CustomerID=Customers.CustomerID
ORDER BY Customers.CompanyName; 

In the second SQL line, how can I go about being able to do

FROM [Customers] 

Instead of

FROM [Northwind].[dbo].[Customers]

Is it possible? or is it not the right way to do it? I have 3 more databases attached to SQL Server by the way and NorthWindis not the only one. I googled it but I am not quite sure what terms to google. I just want to shorten my queries. Thank you

share|improve this question
Please note that it is a good practice to always use schema.tableName instead of just tableName. So even if FROM [Customers] will work when you write 'USE Northwind', you should still always use [dbo].[Customers] instead. –  Nenad Zivkovic May 16 '13 at 12:17
add comment

3 Answers

up vote 3 down vote accepted

There are a few ways that you can do this.

When you open a new query window in SSMS you can add the following line to the top:

    USE Northwind

Or when you open a new query window you can change the database in the dropdown menu on the SQL Editor toolbar to Northwind, see screenshot:

enter image description here

Finally, when working in the Northwind data base, if you open a new query window, it should default to that database.

share|improve this answer
Thanks.Accepted and +1 for your effort for doing [PrintScreen] for the picture illustration. :D –  iAteABug_And_iLiked_it May 16 '13 at 12:02
add comment

At the beginning of your query indicate what database you are using.

USE [Northwind]
share|improve this answer
add comment

Add Use [Northwind] before the query


Select the Northwind database from the database dropdown, if using SSMS


Start a new query window by right-clicking on the Northwind database and selecting new query option

(All are the one and the same thing)

share|improve this answer
add comment

Your Answer


