How to attach a SQL Server database from the command line

前端 未结 3 621
梦毁少年i
梦毁少年i 2021-01-12 03:47

Is it possible to enter a command line command (like in a batch file) to attach a detached database to SQL Server, in stead of opening the management studio and doing it in

3条回答
  •  深忆病人
    2021-01-12 04:14

    If you need to specify the log file name: USE master; GO; CREATE DATABASE DBNAME ON ( FILENAME = 'C:\DBFILE.mdf') LOG ON ( FILENAME = 'C:\DBLOGFILE_log.ldf') FOR ATTACH; GO; And to detach: USE master; GO; EXEC sp_detach_db 'DBNAME', 'true'; GO;

提交回复
热议问题