Sunday, September 28, 2014

Easily attach SQL database to the SQL Server in Few Clicks

To attach SQL database to the Server there are many way but here we discuss on easy way which saves time as well as your extra effort. Byoptimizing SQL Server Management Studio you can tremendously attach SQL database MDF file, LDF file to the SQL Server environment.

Step1: Firstly click on SSMS and then open Database Engine by filling all credential details.


Step2: Then make a click on SQL object explorer and go to database

 

Step3: Then make a right a right clicks on Database 

Step4: Select Attach and click on ADD Button and browse the database MDF file


Step5: On Selecting MDF File just go to Ok to complete the job

 
Step6: You can also attach SQL MDF file without LDF File by removing it after selecting MDF file also.

 

Step7: Check your attached database in a list of Database

 

Another Approach to attach a database by using T-SQLQuery


  1. Establish a connection with Database Engine.
  2. Just click on New Query.
  3. Type in New Query Window the below statement with For Attach close i.e
  4. CREATE DATABASE statement with the FOR ATTACH close. For example
CREATE DATABASE Mypersonalwork
    ON (FILENAME = 'C:\MSSQLServer\Mypersonalwork.mdf'), 
    (FILENAME = 'C:\MSSQLServer\Mypersonalwork_Log.ldf') 
    FOR ATTACH; 
      
Note:
You may also go with sp_attach_db or sp_attach_single_file_db stored procedure. But in future version of Microsoft SQL Server these procedures will be removed. So you must apply this approach which serves a better way to attach SQL MDF Files quickly.

No comments:

Post a Comment