BCP Scripts

A BCP script is simply a batch file or a Windows Script Host file that contains BCP commands. Example 10-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 (Microsoft Press, 2005) and Windows 2000 Scripting Guide (Microsoft Press, 2002).

Example 10-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 pubs..customers ...

Get Microsoft® SQL Server™ 2005 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.