SQL SERVER – RUN T-SQL SCRIPT FILES USING SQLCMD WITHOUT OPEN IN SSMS

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
  1. Open a command prompt window.
  2. 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

  1. Press ENTER.


It will give us result set and shown in command prompt window like below




















To save this output to a text file

  1. Open a command prompt window.
  2. In the Command Prompt window, type: 
sqlcmd -S myServer\instanceName -i D:\ SQLCmdSample.sql -o D:\Result.txt
  1. 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.



author

Kiran Reddy A

Kiran has been a part of the IT industry for more than six years and Involved in many MSBI projects and product development with extensive usage of ETL and Reporting tools like SQL Server Integration Services (SSIS), SQL Server Analysis Services (SSAS), SQL Server Reporting Service (SSRS) and T-SQL

Get Free Email Updates to your Inbox!

www.CodeNirvana.in

Powered by Blogger.

Translate

Total Pageviews

Copyright © Journey to MSBI World With Kiran Reddy | Blogger Templates | Designed By Code Nirvana