Chapter 10. Scripts and Batches

Geez. I've been writing too long. For some reason when I see the phrase "Scripts and Batches" it reminds me of the old song "Love and Marriage." While scripts and batches do go together likea horse and carriage, they are hardly as lyrical — but I digress....

We have, of course, already been writing SQL scripts. Every CREATE statement that you write, every ALTER, every SELECT is all (if you're running a single statement) or part (multiple statements) of a script. It's hard to get excited, though, over a script with one line in it — could you imagine Hamlet's "To be, or not to be...?" if it had never had the following lines — we wouldn't have any context for what he was talking about.

SQL scripts are much the same way. Things get quite a bit more interesting when we string several commands together into a longer script — a full play or at least an act to finish our Shakespeare analogy. Now imagine that we add a more rich set of language elements from .NET to theequation — now we're ready to write an epic!

Scripts generally have a unified goal. That is, all the commands that are in a script are usually building up to one overall purpose. Examples include scripts to build a database (these might be used for a system installation), scripts for system maintenance (backups, Database Consistency Checker utilities (DBCCs) — scripts for anything where several commands are usually run together.

We will be looking into scripts during this chapter, and adding ...

Get Professional SQL Server™ 2005 Programming 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.