通过批处理执行sql命令:
1. Restore.bat文件内容:
osql -E -S -i C:\TempDB\Restore.txt
2. Restore.txt文件内容:
use master
if exists (select * from sysdevices where name='TruckDB')
EXEC sp_dropdevice 'TruckDB'
Else
EXEC sp_addumpdevice 'disk','TruckDB', 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\TruckDB.mdf'
restore database TruckDB
from disk='c:\TempDB\TruckDB'
with replace
导出数据到txt:
/*导入*/
EXEC master..xp_cmdshell 'bcp "test..mintest" in d:\mintest2.txt -c -Sd02 -Usa -P'
/*导出*/
EXEC master..xp_cmdshell 'bcp "test..min" out d:\mintest2.txt -c -Sd02 -Usa -P'