Tuesday, February 11, 2025

sql server - How to run export script by sqlcmd

In command.sql is stored SQL select script, this calling performs it and save output to output.txt.

The param "-h -1" removes title row.
sqlcmd -S localhost\sqlexpress -d username -U sa -P password -h -1 -m 1 
-i "c:\dir\command.sql" -o "c:\dir\output\output.txt"