On Windows using SQLCMD
, we have at least 2 ways to output logs to some logfile. Either we can use option -o
with specified file name, or we can redirect output via console redirect >>
to append to a new file. I prefer using the 2nd option.
sqlcmd -d myDb -P pass -U user -H myHost -i F:\sqlScript.sql -o F:\log.txt
sqlcmd -d myDb -P pass -U user -H myHost -i F:\sqlScript.sql >> F:\log.txt
From my experience, whenever I run longer queries, I don't receive output to the log file immediately, but right after the query is completed. Is there a way to force output to the file immediately?
(I feel that this might be related to both sql query/session settings and the sqlcmd/cmd settings.)
This question can be considered as a follow up on SQLCMD command, How to save output into log file .