Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQLCMD Batch File Syntax Question

Author  Topic 

BellaScout
Starting Member

25 Posts

Posted - 2009-02-21 : 14:15:34
I'm trying to accomplish the following in a cmd batch file but don't know the syntax...I tried just putting it in a batch file but it fails...so I'm missing something.

SQLCMD -S server/sqlexpress
use master
go
sp_detach_db 'dbasename.mdf'
go
sp_attach_db 'attachdbname.mdf', 'c:\mdflocation\mdffile.mdf', 'c:\ldflocation\ldffile.ldf'
go

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2009-02-21 : 18:33:55
Take the .mdf out of the database names, that's part of the file names but not the database name - in fact the database name is completely separate from the file name/s as a database has at least two and can have many files associated with it.
Go to Top of Page
   

- Advertisement -