Run Large SQL script for multiple Inserts with SqlcmdPosted: July 24, 2015
You can use sqlcmd utility to run T-SQL statements or sql scripts. When you have difficulty to run large sql statements in SSMS, you can try to run the script through a command window or Powershell window.
The sqlcmd Utility’s official documentation page:
The file size of datascript.sql is about 100M and it has multiple rows of insert command generated through Visual Studio Data Comparison result.
Some of the Inserts content in my SQL script file have the value $, so I need to use the disable variable substitution flag -x to disable the variable swap.
The final script looks like this:
sqlcmd -S MC\MSSQL2014 -i "C:\temp\datascript.sql" -x -o "C:\temp\outputfile.txt"
The script can be run through Powershell or cmd window.
An easy way to run this script is from Visual Studio to use teh Update Target command, but I need a script to share with other developers for these inserts.