As a default SQLCMD uses windows authentication for connecting to the SQL Server, if running it from the same machine on which SQL Server is installed then there is no need to give the -S [Server name \ instance name] and login credentials.
To run a script create the SQL in a text file rename that to .sql and can be run using this command on the machine hosting SQL Server:
USE Advantureworks;
GO
select * from clients
GO
After that from the command prompt run this command:
c:\>sqlcmd -i C:\myscript.sql -o c:\result.txt
This command will invoke SQLCmd and using windows authentication connect to the default instance of SQL Server, run the query stored in the MyScript.sql file and will store the result in the Result.txt file.
No comments:
Post a Comment