Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 Stop a batch in the even of an error

Author  Topic 

Vets5
Starting Member

2 Posts

Posted - 2010-08-27 : 05:57:49
Hi,

I am trying to write a batch script to call a number of .sql update scripts.

The problem is we need to put something into the back and/or sql files so that if one sql file has an error or fails the entire batch will stop and it will not simply move onto the next file.

Any help is great,

Thanks,

Vets

Vets5
Starting Member

2 Posts

Posted - 2010-08-27 : 06:09:48
quote:
Originally posted by Vets5


The problem is we need to put something into the back and/or sql files so that if one sql file has an error or fails the entire batch will stop and it will not simply move onto the next file.


Vets




Should say batch not back!
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-08-27 : 06:15:11
I'm not 100% sure but if you use the sqlcmd utility and specify multiple files in the -i parameter they will be processed in order and I *think* that if one of them fails the script will terminate.

-> http://msdn.microsoft.com/en-us/library/ms162773.aspx

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2010-08-27 : 06:24:10
What scripting laguage are you using? You could handle this using the status returned from sql server and continue/break basis that. For eg: unix has something called $status
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-08-27 : 08:49:06
make a SQL Agent job, each script in it's own job step. in the advanced properties of each step, set it to quit the job reporting failure on failure of the step.
Go to Top of Page
   

- Advertisement -