Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Attach a Pubs Database in SQL Server

DZone's Guide to

How to Attach a Pubs Database in SQL Server

With the Pubs database ready, you can start learning database concepts and programming and attach any database if you have the MDF and LDF files.

· Database Zone
Free Resource

Download the Guide to Open Source Database Selection: MySQL vs. MariaDB and see how the side-by-side comparison of must-have features will ease the journey. Brought to you in partnership with MariaDB.

In this tutorial, I will explain how to attach a Pubs database in SQL Server. The procedure is the same for every database. You will need Pubs MDF and LDF files to attach to your SQL server.

Both Northwind and Pubs databases come together with the download file.

Installing the Pubs Database

First, download the setup file from the Microsoft Website.

Download Pubs Database

After downloading, you will get a SQL2000SampleDb.msi file (which is a setup file).

msi file

Double-click SQL2000SampleDb.msi to start the setup for Microsoft SQL server 2000 sample database scripts.

Microsoft SQL Server 2000 Sample Database Scripts

Click Next.

You will see the License Agreement window. Select I Agree and click the Next button.

License Agreement Window

Next, you will see the Choose Installation Options window. Click the Next button here, too.

Choose Installation Options

Next, you have to confirm the installation. Click the Next button again.

Confirm Installation Window

The setup procedure will start and soon you will get the Installation Complete message.

Installation Complete Window

The Pubs and Northwind databases will install in the location C:\SQL Server 2000 Sample Databases.

Pubs Database Location

Attach Pubs Database in SQL Server

We now have the Pubs database LDF and MDF files and we are ready to attach them in the SQL server.

In your SQL server’s Object Explorer, right-click the Databases node and select New Database.

New Database in Object Explorer

The Attach Databases window opens and asks for the MDF file, so click the Add button.

Attach Databases Window

Now, you will see the Locate Database Files window. In this window, select PUBS.MDF file (location C:\SQL Server 2000 Sample Databases). Then click the OK button.

Locate Database Files

The Locate Database Files window closes and you will see the Attach Databases window now have the pubs.mdf file location. Click the OK button.

Attaches Databases Window Contains Pubs mdf File Location

The window closes and you will find the Pubs database attached in your SQL server.

Pubs Database

Conclusion

With the Pubs database ready, you can start learning database concepts and programming, such as:

This concludes this tutorial. Now, you can attach any database if you have the MDF and LDF files.

Interested in reducing database costs by moving from Oracle Enterprise to open source subscription?  Read the total cost of ownership (TCO) analysis. Brought to you in partnership with MariaDB.

Topics:
sql server ,database ,tutorial ,pubs

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}