5,443,978 members and growing! (20,319 online)
Email Password   helpLost your password?
Database » Database » SQL Server     Beginner License: The Code Project Open License (CPOL)

HOWTO: Install the Northwind and Pubs Sample Databases

By Brian Hart

To save you from hunting through the docs and locating downloads, we gather both databases here and walk you through installing them using SQL Server Management Studio Express.
C#, SQL, Windows, .NET, Visual Studio, SQL 2005, SQL Server, DBA, Dev

Posted: 23 Oct 2007
Updated: 23 Oct 2007
Views: 13,225
Bookmarked: 17 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
17 votes for this Article.
Popularity: 3.53 Rating: 2.87 out of 5
3 votes, 17.6%
1
3 votes, 17.6%
2
0 votes, 0.0%
3
4 votes, 23.5%
4
7 votes, 41.2%
5

Introduction

The Northwind and Pubs sample databases are staples of other sample code on this and other development websites. They are used in countless tutorials and walkthroughs published by Microsoft and others. Being a SQL/SQL Server newbie myself, I figured there may be others in my boat who might want both databases in an easily-accessible spot, and an easier, less error-prone way of installing them into SQL Server 2005 Express Edition than, say, running SQL Query scripts.

Background

It's lost on me why one must use *.sql query scripts to install these samples. It's also lost on me why SQL Server distributions don't come with these databases provided, since they are used so ubiquitously through documentation, websites and tutorials. There are probably several good reasons for this. However, I am focused on usability and not on making things harder than they have to be.

There undoubtedly will be readers of this who will protest and say that I should use *.sql query files whenever possible; this is good and a perfectly acceptable practice. I see this article as illustrating just another way to accomplish a similar objective.

It's worth noting, for example, that a default Visual Studio.NET 2005 Standard Edition installation does not distribute these databases. It goes part-way, creating a Program Files\Microsoft Visual Studio 8\SDK\Samples\Setup directory containing, e.g., instnwnd.sql, a query script that ostensibly can be used to install the Northwind sample database.

However, hats off to Microsoft for putting apples with apples. Microsoft provides the queries for installing, but not the *.mdf and *.ldf files for the databases themselves. This does not support users in installing these important samples into SQL Server. Perhaps there's an easier way: this article. The download attached to this article contains the SQL Server 2000 versions of these files and a tutorial on installing them using SQL Server 2005 Express Edition.

Personally, I favor using graphical (GUI) tools and methods over typing cryptic commands and deciphering error messages. So, this article illustrates how to install Northwind and Pubs using graphical tools and methods.

Steps: Installing the Northwind and Pubs Databases

Note: The Steps above make use of SQL Server Management Studio Express, which sometimes doesn't install along with a Microsoft SQL Server 2005 Express Edition install. For this case, SQL Server Management Studio Express is available as a separate download from Microsoft.

Step 1: Using the Download link above, download the ZIP file containing the following files. Extract the files to a directory on your computer and remember where you put them. For these steps to work, you must have the following files on your computer:

  • NORTHWND.MDF
  • NORTHWND.LDF
  • PUBS.LDF
  • PUBS.MDF

Step 2: On the Start menu, point to Programs, point to Microsoft SQL Server 2005 and then click SQL Server Management Studio Express.

  • SQL Server Management Studio starts and displays the Connect to Server window, shown in Figure 1.
Screenshot - InstallNorthwindAndPubs_fig1.jpg

Figure 1. The Connect to Server window

Step 2: Fill in the appropriate settings on the Connect to Server window that appears and then click Connect.

  • SQL Server Management Studio Express opens the Object Explorer with the server's databases displayed.

Step 3: Right-click the Databases folder and then click Attach, as shown in Figure 2.

Screenshot - InstallNorthwindAndPubs_fig2.jpg

Figure 2. The Object Explorer window

Step 4: In the Attach Databases window, click Add....

  • The system prompts you for the proper *.mdf file using the Locate Database File window, as shown below in Figure 3.
Screenshot - InstallNorthwindAndPubs_fig3.jpg

Figure 3. The Locate Database File window

Step 5: Locate and click on the NORTHWND.MDF file, and then click OK.

  • The right pane of the Attach Databases window will look as shown in Figure 4.
Screenshot - InstallNorthwindAndPubs_fig4.jpg

Figure 4. The right pane of the Attach Databases window after adding the Northwind database

Step 6: Repeat steps 4 and 5 for the PUBS.MDF file.

  • When you're done, and if you did the proper actions, the right pane of the Attach Databases window should look as displayed in Figure 5.
Screenshot - InstallNorthwindAndPubs_fig5.jpg

Figure 5. The right pane of the Attach Databases window after adding the Pubs database

Step 7: In the Attach Databases window, click OK.

Step 8: To check that everything was successful, in the Object Explorer window, click the plus sign to open the Databases folder.

  • The Northwind and Pubs databases will be displayed, as shown in Figure 6.
Screenshot - InstallNorthwindAndPubs_fig6.jpg

Figure 6. The Object Explorer after importing the Northwind and Pubs databases

Where To Go for Help

Feel free to email me with specific questions about this article and I will be happy to explain. I also want to invite you to make use of the forums at the bottom of this article. I wish you well and happy programming.

History

In this section, I will keep a running history of the changes and updates I've made to this article.

  • 16 Oct 2007, 2:13 PM Pacific: Article written

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Brian Hart


I am a Ph.D. graduate in X-Ray Astrophysics at the University of California, Irvine, near Newport Beach. I study the shapes and brightnesses of clusters of galaxies in the X-rays in an attempt to understand the way dark matter and dark energy are distributed throughout the Universe.

In my spare time, I enjoy singing and music, and also like to take long road trips. In addition, I also enjoy spending time on the weekends doing volunteer house construction with Habitat for Humanity.
Occupation: Web Developer
Company: Financial Statement Services, Inc.
Location: United States United States

Other popular Database articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 6 of 6 (Total in Forum: 6) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralSQL Server 2008memberJerry Evans8:25 28 Aug '08  
GeneralRe: SQL Server 2008memberBrian Hart9:36 28 Aug '08  
Generalthank u for creating this articlemembersekhartome16:19 1 Aug '08  
GeneralWith Vista you may need to run SQL Studio Management Express as an administratormembercwcycwcy2:19 2 Jun '08  
GeneralRe: With Vista you may need to run SQL Studio Management Express as an administratormemberBrian Hart9:36 28 Aug '08  
GeneralWonderfulmemberTheAndruu7:44 29 Nov '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 23 Oct 2007
Editor: Genevieve Sovereign
Copyright 2007 by Brian Hart
Everything else Copyright © CodeProject, 1999-2008
Web11 | Advertise on the Code Project