Wednesday, 19 March 2014

Run MSSQL SQL Script from command line

Sometime, SQL script that we need to import is very huge and is not possible to open from Microsoft SQL Server Management Studio. Do not worry, we have an option to run the script from command line. Using the following command you can run the sql scripts from command line.

To run the script file

1. Open a command prompt window.
2. In the Command Prompt window, type:

    sqlcmd -S MSSQLServer/ServerInstance -i ScriptFileName.sql

3. Press ENTER.

To save this output to a text file

1. Open a command prompt window.
2. In the Command Prompt window, type: 
   
   sqlcmd -S MSSQLServer/ServerInstance -i ScriptFileName.sql -o C:\OutputFileName.txt 

3. Press ENTER.

No comments:

Post a Comment