The code which I have used in this code is over here:
-- Detach Database USE [master] GO EXEC MASTER.dbo.sp_detach_db @dbname = N'AdventureWorks2014_new' GO -- Deprecated Way to Attach Database USE [master] GO EXEC MASTER.dbo.sp_attach_db 'AdventureWorks2014_new', 'E:\AdventureWorks2012_Data_new.mdf', 'E:\AdventureWorks2012_log_new.ldf' GO -- Correct Way to Attach Database USE [master] GO CREATE DATABASE [AdventureWorks2014_new] ON ( FILENAME = 'E:\AdventureWorks2012_Data_new.mdf'), ( FILENAME = 'E:\AdventureWorks2012_log_new.ldf') FOR ATTACH GO
Here is the question back to you – Do you still use old methods to attach database? If yes, I suggest that you start using the new method onwards.
SQL in Sixty Seconds Video
I have attempted to explain the same subject in simple words over in following video.
Here are the blog posts I have previously written on the subject of SA password. You can read it over here:
- SQL SERVER – 2005 – T-SQL Script to Attach and Detach Database
- SQL SERVER – Move Database Files MDF and LDF to Another Location
- SQL SERVER – 2005 Take Off Line or Detach Database
- SQL SERVER – Attach mdf file without ldf file in Database
- SQL SERVER – Copy Database from Instance to Another Instance – Copy Paste in SQL Server
You can subscribe to my YouTube Channel for frequent updates.
Reference: Pinal Dave (https://blog.sqlauthority.com)