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.
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 to Suppress the Message. If you want to suppress this message, then you can use the “SET NOCOUNT” statement.
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.
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.
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
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With