SQLCMD
SQLCMD is a command-line utility provided by Microsoft SQL Server that enables you to connect to a SQL Server instance and run T-SQL commands and scripts from the command prompt.
SQLCMD mode can be used from SSMS as well
Here are some examples of how to use SQLCMD:
Connect to a SQL Server instance using SQL Server authentication:
sqlcmd -S MyServer -U MyUser -P MyPassword
Run a script from a file:
sqlcmd -S MyServer -U MyUser -P MyPassword -i C:\MyScript.sql
Run a script and save the output to a file:
sqlcmd -S MyServer -U MyUser -P MyPassword -i C:\MyScript.sql -o C:\MyOutput.txt
Execute a single T-SQL command:
sqlcmd -S MyServer -U MyUser -P MyPassword -Q "SELECT * FROM MyTable"
Comments
Post a Comment