Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft SQL Server > Re: Creating a ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 11181 of 11420
Post > Topic >>

Re: Creating a database from set of TSQLl files

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 ?
 




 2 Posts in Topic:
Creating a database from set of TSQLl files
Annonymous Coward <me@  2008-06-26 10:31:22 
Re: Creating a database from set of TSQLl files
"Dan Guzman" &l  2008-06-26 07:44:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 8:51:38 CDT 2008.