Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we tell sqlcmd to continue "on error" with next batch?

Any ideas on how to accomplish this?

USE [db_name]
BEGIN TRANSACTION
...TONS OF INSERTS
COMMIT;
RAISERROR (..) WITH NOWAIT;  //If error continue with next batch

BEGIN TRANSACTION
...TONS OF INSERTS
COMMIT;
RAISERROR (..) WITH NOWAIT;

...
like image 682
Newbie Avatar asked Jul 23 '09 20:07

Newbie


People also ask

How can I tell if SQLCMD is working?

You can test SQLCMD.exe from a Powershell console, running as the Delphix OS user, on the Windows host where Delphix Connector service is running.

What is the purpose of using SQLCMD Q command?

The sqlcmd utility lets you enter Transact-SQL statements, system procedures, and script files through a variety of available modes: At the command prompt. In Query Editor in SQLCMD mode.


1 Answers

Use the -V flag on the command-line. If you set a sufficiently large enough value (e.g 17), even fairly severe errors will not stop the script.

e.g. sqlcmd ... -V 17 -i MyFile.sql

I will assume that you know what you're doing when you do this and are monitoring the error messages nonetheless.

You could go higher, up to level 25, but if you're getting errors between level 17 and 25, it's unlikely that you're going to be able to progress much because they tend to be caused by software or hardware errors on the server, rather than errors in the scripts you're inputting.

like image 122
user1738833 Avatar answered Sep 21 '22 10:09

user1738833