Attach database using sqlcmd

USE [master]
GO
CREATE DATABASE [database_name] ON
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Data\<database name>.mdf' ),
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Data\<database name>.ldf' )
FOR ATTACH ;
GO

Atau cara lain:

use master

go

sp_detach_db '<databasename>'

use master
go
sp_attach_db '<databasename>','path\to\mdf','path\to\ldf'
go

Tagged with: ,
Posted in CodeLog
2 comments on “Attach database using sqlcmd
  1. […] wizard, I’m guessing that there’s a related interface in sqlcmd, something like this or this.  I believe that there’s an easy way to execute .sql scripts from the SQL Server Management […]

  2. Does your website have a contact page? I’m having trouble locating it but, I’d like to send you an email.
    I’ve got some recommendations for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it grow over time.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: