In Software World, Source of Knowledge is requirement
J.Today I got big SQL Script (600 MB) to execute in SSMS. But due to big file it was not opened in SSMS. So I was searching for solution to execute this file without opening .sql file in SSMS, I found solution in by using sqlcmd we can able to run a Transact-SQL script file. By using SQLCMD we can execute any type SQL Scripts.
To demonstrate, how to use SQLCMD. I have taken simple SQL Script and saved in Notepad and given name as SQLCmdSample.sql and Save the file in D Drive
To run the script file
- Open a command prompt window.
- In the Command Prompt window, type:
sqlcmd -S myServer\instanceName -i D:\ SQLCmdSample.sql
In my case I am using my local machine as SQL
Server so I using ‘.’ As Server name.
i.e.
sqlcmd -S . -i D:\ SQLCmdSample.sql
- Press ENTER.
It will give us result
set and shown in
command prompt window like below
To save this output to a
text file
- Open a command prompt window.
- In the Command Prompt window, type:
sqlcmd
-S myServer\instanceName -i D:\ SQLCmdSample.sql -o D:\Result.txt
- Press ENTER.
No output is returned
in the Command Prompt window. Instead, the output is sent to the Result.txt
file in D drive. We can verify this output by opening the Result.txt file.