Attaching A Database

Obtain and install AdventureWorks

First, go to Microsoft’s site to download a copy of AdventureWorksdb.msi, the program that installs AdventureWorks. Then copy this file to your computer, as well as the related file, AdventureWorksBI.msi (BI stands for Business Intelligence).Running these installation files places the two databases on your hard disk, but it does not actually install them. There are two ways to install the databases: You could use the new sqlcmd utility, which looks a lot like a DOS window; or, you could use the graphical interface. We’ll look at both techniques.

Method #1

  1. Run SQL Server Management Studio.
  2. Open a sqlcmd window by clicking on the toolbar button that is the eighth one from the right (it’s got a picture of a grid with a red exclamation point over it).
  3. Enter the command:
Exec sp_attach_db @dbname=N'AdventureWorks', @filename1=N'C:/Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/Data/AdventureWorks_Data.mdf', 
 @filename2=N'C:/Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/Data/AdventureWorks_log.ldf'

Note: You may have to adjust the specific file locations if your installation differs from the default.

Method #2

This method attaches databases via the graphical interface. Besides saving you all that typing, the graphical interface lets you attach more than one database in a single action. To do this, follow these steps:

  • Select the Databases node in the Object Explorer.
  • Right-click the mouse and select Attach on the tear-off menu, which opens the Attach Database dialog box.
  • Click the Add button, and then navigate to the location of the database file(s) you wish to add. (You may select as many databases as you wish and attach them all at once.)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s