Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to suppress "x rows affected" in SQLCMD from the command line?

Is there a way to suppress "x rows affected" in SQLCMD from the command line?

I'm running an MSBuild script and don't want it clogging up my log on my build server.

I'd rather not have to add "SET NOCOUNT ON" in every script, so if there's a way to do it from the command line, that would be fantastic.

like image 912
Josh Kodroff Avatar asked Jan 06 '10 15:01

Josh Kodroff


People also ask

How do I stop rows being affected in SQL Server?

If you do not want to know how many rows were impacted by your SQL Statement, it is a good idea to use SETNOCOUNT ON and turn off the message. In simple words, if you do not need to know how many rows are affected, SET NOCOUNT ON as it will reduce network traffic leading to better performance.

How do you suppress in SQL?

How to Suppress the Message. If you want to suppress this message, then you can use the “SET NOCOUNT” statement.

How do I turn off hyphens in SQLCMD?

use the -h -1 option to remove the dashes (--------) from the output and SET NOCOUNT ON to remove the "rows affected". This is great if you're creating a report or CSV file for another system to process. You don't need to use a union between your select statements for this.

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.


3 Answers

What about creating a startup script with SET NOCOUNT ON in the script (assign the script to the SQLCMDINI environment variable). http://msdn.microsoft.com/en-us/library/ms162773.aspx

like image 80
fupsduck Avatar answered Oct 09 '22 13:10

fupsduck


The -i and -q options are mutually exclusive.

Create a file named setnocount.sql with the content:

SET NOCOUNT ON;

And you might be able to do -i setnocount.sql,otherscript.sql using the multiple files feature and effectively an "included" common first file.

like image 27
Cade Roux Avatar answered Oct 09 '22 14:10

Cade Roux


You can also run multiple lines in the -Q parameter, separated by semicolon, like below

eg:

-Q "set nocount on;select * from table;delete from table where some_condition=true"
like image 46
Rob Avatar answered Oct 09 '22 12:10

Rob