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

Sql ServerRowsSqlcmdSuppress

Sql Server Problem Overview


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.

Sql Server Solutions


Solution 1 - Sql Server

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

Solution 2 - Sql Server

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.

Solution 3 - Sql Server

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"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJosh KodroffView Question on Stackoverflow
Solution 1 - Sql ServerfupsduckView Answer on Stackoverflow
Solution 2 - Sql ServerCade RouxView Answer on Stackoverflow
Solution 3 - Sql ServerRobView Answer on Stackoverflow