by "Dan Guzman" <guzmanda@[EMAIL PROTECTED]
>
Jun 26, 2008 at 07:44 AM
> The batch part I can largely figure out myself. So my question basically
> can be simplified as:
>
> How can I read and execute TSQL commands from a file - AND return an
> success/error code ?
You can execute scripts using SQLCMD command-line utility with the -b
parameter. This will cause the utility to exit with a non-zero return
code
if an error with a severity > 10 is raised. For example:
SQLCMD -E -S MyServer -d MyDatabase -b -i MyScript.sql
IF NOT %errorlevel% == 0 GOTO :MyErrorLabel
--
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
"Annonymous Coward" <me@[EMAIL PROTECTED]
> wrote in message
news:TuqdneB7p6Ea_P7VRVnytAA@[EMAIL PROTECTED]
>I have written a set of sql files that make my entire database schema. I
>have divided the schema into seperate files mostly for "manageability"
(for
>example, I can check error codes as I go along, and terminate the process
>as soon as an error occurs).
>
> I have several tsql files in a directory, and I want to be able to write
a
> batch script (or something similar), which allows me to:
>
> 1). Process each of the individual files (i.e. execute the commands in
the
> file)
> 2). re****t succes or failure for the file
> 3). Abort the entire process if a command in one of the files failed
>
> The batch part I can largely figure out myself. So my question basically
> can be simplified as:
>
> How can I read and execute TSQL commands from a file - AND return an
> success/error code ?