Click here to Skip to main content
Click here to Skip to main content

HowTo: Install the Northwind and Pubs Sample Databases

By , 19 Jul 2012
 
Note: SQL Server 2008 Users Click Here for the SQL Server 2008 version of this article

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 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.

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 here 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

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. Click here for the SQL Server 2008 version of this explanation.

History

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

License

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

About the Author

Brian C Hart
Software Developer (Senior) Corrugated Technologies, Inc.
United States United States
From Fridley, Minnesota and I like computer programming! When I got started, I was working mostly with Windows GUI programming in C/C++. Then later on I worked with COM/DCOM for a school internship. I used COM/DCOM to write an ad hoc cluster server and job-running environment for a cluster of 24 Windows-based high-end visualization workstations. I moved on to C# and have been working in C# and Windows Forms ever since. I have yet to embrace Silverlight Smile | :)
Follow on   Twitter

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralGood ArticlememberAlireza_13627-May-13 17:58 
Thanks a bunch
Questionit is really nicememberMember 990282911-Mar-13 18:54 
thankyou so much for such a great help
GeneralMy vote of 5memberSavalia Manoj M27-Feb-13 16:55 
Excellent work...!!
GeneralMy vote of 5memberWhiteOsoBDN26-Feb-13 2:46 
Good
GeneralMy vote of 5memberpron116-Jan-13 15:38 
great explanation. thanks you.
QuestionSQL Server 2005 Install/UpgradememberGoldstar Lee13-Jan-13 6:49 
Hi Brian,
 

I have been using Visual Studio 2010 quite sometime, but this is the first time I try to use the Microsoft SQL Server 2005.
 
My SQL server was installed as part of the Visual Studio 2010 package.
 
My questions:
 
(1) From Windows 7, START -> All Programs, I cannot find the "Microsoft SQL Server 2005". However, from Install/Uninstall Programs, I can see "Microsoft SQL Server 2005" (missing "Express") is there. But it does NOT have the size and Version information. Immediately underneath it, though, there is an entry of "Microsoft SQL Server 2005 Compact Edition [ENU]", complete with the date and version.
 
My question is : is the Microsoft SQL Server 2005 installed PROPERLY on my computer or not ? Why the "Express" is omitted ?
 
(2) When I tried to updater the SQL server 2005, with the Service Pack 4 or 3, (login as Administrator and "run" the downloaded file from the Command prompt), it failed with a message that the product was already there, and I should select the "Upgrade" to proceed. But there is No "Upgrade" to select from.
 
My Question is: I am not sure whether the SQL Server is installed properly on my computer (Question 1 above), but, should I Uninstall it first to avoid the problem in Question 2 ? Do I need to uninstall/Install just the SQL Server 2005, or the ENTIRE Visual Studio 2010 ?
 
Thanks very much,
Golden Lee
GeneralMy vote of 5memberAmol_B1-Jan-13 23:18 
Most Quick way to do it
Questionspot on explanationmemberJim Millecam19-Dec-12 9:53 
Brian, Spot on explanation. I surfed through MSDN and anything I could find to add Northwnd DB on my system. This explanation was clear and got the job done in less than 5 minutes. Thanks.
Questionhihi thanksmemberhaiyentink1025-Oct-12 15:26 
Thumbs Up | :thumbsup:
GeneralEasy as it getsmemberMember 950286110-Oct-12 14:50 
Thanks, that was too easy. I installed on SQLServer2008R2 on Windows 7 64 bit. Smile | :)
QuestionThanks so muchmemberRonnieVN3-Aug-12 22:11 
Thanks "Code Project" so much
QuestionConnect to Server?membermetonym19-Jul-12 5:30 
How do I get the information for Step 2, "Fill in the appropriate settings on the Connect to Server window"? Where do the settings come from? If I click on "browse" the server list is empty. Do I have to start a server first?
 
I'm new to SQL Server, I just wanted to have a Northwind Database to have some test data in Visual Studio.
AnswerRe: Connect to Server?memberBrian C Hart19-Jul-12 6:05 
You know when you start SQL Server management studio, you see a screen like in the picture in Figure 1.
 
You have to have an "instance" of SQL Server installed on your computer first. To get a free version of SQL Server to put on your machine, go Google search on "Microsoft SQL Server 2005 Express Edition with Advanced Tools" and download whatever you find, and just put the defaults in the installation dialogs.
 
If you are just by yourself putting a SQL Server Express on your own dev box then the settings inside the picture shown should be the same as on your computer. Just hit OK.
 
If not, then you should ask whoever is in charge of your database (your company's DBA) about what settings you are supposed to put.
 
Was that helpful?
 
Brian
Sincerely Yours,
Brian Hart

GeneralRe: Connect to Server?membermetonym22-Jul-12 23:23 
Thanks a lot!
QuestionThanks Brianmembersandeep1967-Jun-12 23:20 
Thanks Brian
QuestionTHANKS VERY MUCHmemberpofante7-Jun-12 0:09 
I Attach it to Microsoft Sql Server 2008 Successed
QuestionThanksmemberMrNilesh4-Jun-12 20:54 
This is really helpful.
QuestionThanksmemberMember 858559930-Apr-12 10:31 
Finally something to do with an SQL Server installation that (thanks to your article) was easy, and actually worked! As an SQL newbie, it's a relief to discover that it _can_ happen Smile | :)
QuestionThanksmemberMuhammad Tausif29-Apr-12 16:20 
Thanks
GeneralThanks BrianmemberMember 857561217-Jan-12 14:03 
Brian,
Yet another thank-you for your guide to the Northwind dtabase. I tried a couple of other sources with no success, but yours was spot-on.
 
Best,
Bryan
GeneralThanks!!! [modified]memberCNote883-Jan-12 3:01 
This was what I was looking!!!

modified 3-Jan-12 9:23am.

Questionmy vote for 5membercostavo17-Dec-11 11:35 
It is an excellent tutorial for extreme beginners...
GeneralMy vote of 5memberPomel16-Jun-11 7:10 
Still useful, still relevent, thanks!
GeneralMy vote of 5membertebogoph19-Apr-11 0:21 
works pefk
GeneralMy vote of 5memberAnup Daware10-Apr-11 20:27 
Does exactly what the article is about, nothing less nothing more.
GeneralMy vote of 5memberhbtb8-Apr-11 3:48 
simple
GeneralInstalling Northwind data basememberMember 209771228-Sep-10 22:25 
I tried as per instruction, but somehow I have problems in creating Database Diagram giving a message that there is no valid "owner"
 
I check the Database files property - the Owner is already specified
 
anyone knows how to solve this problem? I am new to database world!
GeneraldownloadmemberSmon the Vidd10-Aug-10 2:10 
Thanks Brian - that's worked and got me started on the practical side of a course I'm doing
GeneralMy vote of 5membersandeepraju2-Aug-10 21:33 
THANks, it helped me a lot, keep up the god work
GeneralMy vote of 5memberMikJr27-Jul-10 14:38 
It works -
GeneralIf you are running SQL Server 2008 under Windows 7memberDHCut25-Feb-10 0:41 
Hi
Thanks for excellent article.
Just a note to say that if you are operating Vista or Windows 7
(This is obvious if you already know the answer!)
You need to explicitly start SQL Server Management Console "as Administrator" (even if you are logged in to Windows as an Admin).
This is easy to do.
1 Make sure you log in to Windows 7 operating system as a user that is in the Administrators Group.
(If you are the only user set up, you will probably be the domain Admin anyway).
2 Don't start SQL Server Management Console from the start button using a left click. Use a right click and select "Run as administrator" from the popup submenu.
Why?
(The reason for this is that Windows 7 and Vista use a subsystem called UAC (User Account Control). This means that even if you are logged in as Admin, you don't get all the Admin privileges straight off. You need to elevate!
 
Also: Brian you were saying in your article:
"It's lost on me why one must use *.sql query scripts to install these samples."
(Well, I know what you mean. ?Why the nerdy scripts?)
The main reason is that you don't need to be a human to install a script. Other computers can run batch jobs on their own. This would be relevant if you were setting up 20 installations for a training course.
You could telnet on to a remote computer and install the necessary using the command line.
Also:-
Scripts are useful if you are working on a server (as opposed to a pc) which either doesn't have Windows on it, or if you don't have a graphics screen to see the gui. All you need is the naked command-line.
Also, SQL Server Management Console is a separate install and not all servers have it.
(Anyway, thank goodness for the GUI and Management Console). In the good old days, where engineering was required to design an installation, servers were so small that if you'd loaded Management Console, it would eat up quite a percentage of capacity that would be better left for the data.)
 
Thanks for writing such a useful article.
(In defence of Microsoft, it's all mostly in the accompanying readme file (but without the screenshots.)
Smile | :) Dave
GeneralMy vote of 1membercortega8-Oct-09 4:36 
It's needed to remark that this article is for begining people
GeneralRe: My vote of 5memberARon_8-Oct-09 7:41 
A vote of 1. That is bit harsh. The title itself implies it is for beginners. Look at some of the other articles that are rate as a 1 and you see this is not that bad. Poke tongue | ;-P
 
ARon

GeneralThanksmemberKumarIyer29-Sep-09 11:05 
Hey thanks for this Northwind installation article! I used it and it really helped me.
 
Thanks so much!
GeneralNorthwind Connection ProblemsmemberNathanlc12-Mar-09 19:08 
Hi,
My computer installed SQL 2008 for me with the packet. When I download Northwind Database, I try to connect by clicking on attach database file and it says this
 
"Unable to open the physical file "C:\SQL Server 2000 Sample Databases\Northwind.MDF".
Operating system error 5: "5(Access is denied.)"/
An attempt to attach an auto-named database for file C:\SQL Server 2000 Sample Databases\Northwind.MDF failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
 
What can I do??
NewsNorthwind and Pubs for SQL 2000 and up from MicrosoftmemberMember 109431628-Jan-09 20:53 
You can find official Microsoft versions of these databases at : http://code.msdn.microsoft.com/northwind/Release/ProjectReleases.aspx?ReleaseId=1401
QuestionAn error provided when attaching the DB filesmembermohanednoon14-Oct-08 1:40 
What i have to do?
An error provided when attaching the Northwind data base file :
 
(same error for both files)
 
TITLE: Microsoft SQL Server Management Studio Express
------------------------------
 
Attach database failed for Server 'MOHAMED-PC'. (Microsoft.SqlServer.Express.Smo)
 
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.2047.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Attach+database+Server&LinkId=20476
 
------------------------------
ADDITIONAL INFORMATION:
 
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.Express.ConnectionInfo)
 
------------------------------
 
Unable to open the physical file "C:\SQL Server 2000 Sample Databases\NewDB\northwnd.mdf". Operating system error 5: "5(‏‏הגישה נדחתה.)". (Microsoft SQL Server, Error: 5120)
AnswerRe: An error provided when attaching the DB filesmembermohanednoon16-Oct-08 0:26 
Ok...thanx anyway i solved the prob.
GeneralRe: An error provided when attaching the DB filesmemberJyotiDudeja20-Feb-09 6:09 
How did you solve this. please help
GeneralRe: An error provided when attaching the DB filesmemberculminIT22-Apr-09 22:51 
I also had this problem. I moved my mdf and ldf files to the normal directory where they are created, when I create a new database from management studio. It has to do with having modify privilages on the SQL account in the folder where the files are located. Hope that helps the next person...
GeneralHOWTO: Install the Northwind and Pubs Sample Databasesmemberrobhelle17-Sep-08 6:43 
Thanks for the insight!
 
- spent half-a-day trying to upload test data into SQL Server 2008 Express edition, prior to viewing your post. Getting up to spped with Silverlight technologies, and test data is best, at this point.
 
Rob
 
www.roberthellestrae.com
GeneralSQL Server 2008memberJerry Evans28-Aug-08 7:25 
Hi
 
I'm trying to do this with SQLS2008 and it will not play ball. The management console claims the file is read-only. I suspect malign forces - are there any tricks I can use here?
 
Thx
 
Jerry
GeneralRe: SQL Server 2008memberBrian C. Hart, Ph.D.10-Oct-09 7:49 
Click here[^] for an article on doing this with SQL Server 2008
 
Brian
 
Sincerely Yours,
Brian Hart

Generalthank u for creating this articlemembersekhartome1-Aug-08 15:19 
hi sir my name is somasekhar
this article is so good.by the use of this article i learn how to install databases and any body want to add more databases click the below link
http://www.codeplex.com/MSFTDBProdSamples[^]
GeneralWith Vista you may need to run SQL Studio Management Express as an administratormembercwcycwcy2-Jun-08 1:19 
With Vista you may need to run SQL Studio Management Express as an administrator to attach the databases.
The steps above only worked when I ran as administrator.
 
I'm not sure why.
GeneralRe: With Vista you may need to run SQL Studio Management Express as an administratormemberBrian Hart28-Aug-08 8:36 
Is this 2005 or 2008?
 
Sincerely Yours,
Brian Hart

GeneralRe: With Vista you may need to run SQL Studio Management Express as an administratormembersparmar548614-Sep-09 0:41 
i made my SQL Studio Management Express as an administrator
and now i can attach northwnd and pubs database
 
thanks for ur help,
 
Sandeep
GeneralWonderfulmemberTheAndruu29-Nov-07 6:44 
Absolutely great walk-through. Exactly what I was looking for, thank you much.
 
Tenui Nec Dimittam

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130617.1 | Last Updated 19 Jul 2012
Article Copyright 2007 by Brian C Hart
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid