DOS executes SQL commands over batch

xiaoxiao2021-03-06  64

Execute the SQL command through the batch:

1. RESTORE.BAT file content:

OSQL-E -S -I C: /Tempdb/Restore.txt

2. RESTORE.TXT file content:

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

Single table export data to txt:

/ * Import * /

Exec master..xp_cmdshell 'bcp "test..mintest" in d: /mintest2.txt -c -sd02 -usa -p "

/ * Export * /

Exec master..xp_cmdshell 'bcp "test..min" OUT D: /MINTEST2.TXT -C -SD02 -USA -P'

转载请注明原文地址:https://www.9cbs.com/read-119674.html

New Post(0)