Attach / Detach Database OSQL Example

This page has examples on how to attach and detach MS SQL Server databases with TSQL commands:

http://www.mssqlcity.com/Articles/Adm/attach_database.htm



To detach:

EXEC sp_detach_db 'pubs', 'false';

- switch the 'false' for 'true' if the database files do not exist.
- don't forget the semi colon.

To attach:

EXEC sp_attach_db @dbname = 'pubs', 
@filename1 = 'C:\MSSQL\Datapubs.mdf',
@filename2 = 'C:\MSSQL\Datapubs_log.ldf'



-----------------

Tags: mount, unmount, osql, remove, offline
Related Scribbles:
  • List Databases MSSQL
  • Restore and Backup MSDE Database with TSQL via OSQL
  • SQL Server


  • ID: 729
    Author:
    leonard
    Date Updated:
    2009-02-22 15:10:13
    Date Created:
    2006-01-03 14:03:26

    Edit

    Comments?
     >> Leonard Chan's Homepage  >> Scribble Web  >> Attach / Detach Database OSQL Example
    leonard.lotus-land.ca is hosted by Perceptus Solutions Inc.