Sunday, February 21, 2010

Attach a SQL DB to SQL Server

To add or attach an existing sql db to sql server, we are required to follow the following steps:

Step 1 : Open the Windows Command prompt by going into START>RUN and type “cmd” and press enter.

Step 2: Type the following code:

sqlcmd -S PAVAN\SQLEXPRESS

where PAVAN\SQLEXPRESS stands for the sql instance in PC, it is independent for every installation or registration. You could get this information from the SQL Configuration Manager program that got installed with the SQL Server (shortcut is placed in Start menu by default).

Step 3: Type the following code:

USE [master]

GO

CREATE DATABASE [MISDBDONE] ON

( FILENAME = N'C:\Pavan\Shared\MIS_DB\MISDB.mdf' ),

( FILENAME = N'C:\Pavan\Shared\MIS_DB\MISDB_log.ldf' )

FOR ATTACH ;

GO

Please fill in the mdf and ldf file paths in the Filename command.  Then execute the code.

And this is how it is done.  Thanks for reading.

No comments:

Post a Comment