Breaking News

Microsoft SQL Server 2016 : Attach a database by using Transact-SQL

Attach a database in SQL Server Management Studio 2016.  





Before attaching the database

1 . Copy (two file e.g. the ‘database.MDF‘ file which contains the primary data, and the ‘database.LDF‘ file which logs) and 
2. Paste "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA" -(copy the file into the default location for data files)

Now we are ready to attach them.

3. Open SQL Server Management Studio....Click on connect button
4.  Press Ctrl+N or Click on new query From the Standard bar...



 CREATE DATABASE AdventureWorks2012
ON 
 (FILENAME='C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\AdventureWorks2012_Data.mdf')
LOG ON 
 (FILENAME='C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\AdventureWorks2012_log.ldf')
FOR ATTACH
5. Copy above code and paste. After paste code click on execute or press F5
Database is now attached.. the result is







1 comment: