方法一:
EXEC sp_attach_db @dbname = N'ManPower',@filename1 = N'D:\ManPower_Data.mdf',@filename2 = N'D:\ManPower_log.ldf'
保存成D:\AttDB.sqlosql.exe -E -S -i D:\AttDb.sql
保存为D:\AttDb.Bat方法二:
use master
if not exists (select * from sysdatabases where name='HSSY'
BEGIN
create database HSSY
END
if exists (select * from sysdevices where name='HSSY')
BEGIN
EXEC sp_dropdevice 'HSSY'
END
Else
BEGIN
EXEC sp_addumpdevice 'disk','HSSY', 'C:\DataBase.db'
END
restore database HSSY
from disk='C:\DataBase.db'
with replace
保存成:C:\AttDb.sqlif not exists (select * from sysdatabases where name='HSSY'
BEGIN
create database HSSY
END
if exists (select * from sysdevices where name='HSSY')
BEGIN
EXEC sp_dropdevice 'HSSY'
END
Else
BEGIN
EXEC sp_addumpdevice 'disk','HSSY', 'C:\DataBase.db'
END
restore database HSSY
from disk='C:\DataBase.db'
with replace
osql.exe -E -S -i C:\AttDb.sql
保存成C:\AttDb.bat