BCP Scripts

A BCP script is simply a batch file or a Windows Script Host file that contains BCP commands. Example 11-3 shows examples of how to run BCP using various scripting options. If you do not know how to use batch files or Windows Script Host, two great resources are Windows Command-Line Administrator’s Pocket Consultant, 2nd Edition (Microsoft Press, 2008) and Windows 2000 Scripting Guide (Microsoft Press, 2003).

Example 11-3. Using BCP in a Script

sched-export.bat

@echo off
@if not "%OS%"=="Windows_NT" goto :EXIT
bcp pubs..customer out customers.txt -c -t, -T
:EXIT

sched-export.vbs

'Nightly Bulk Copy export for the customers table 'Writes output to cust.txt and errors to err.txt Set ws = WScript.CreateObject("WScript.Shell") ret = ws.Run("bcp ...

Get Microsoft® SQL Server® 2008 Administrator's Pocket Consultant now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.