Run Large SQL script for multiple Inserts with Sqlcmd


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:

https://msdn.microsoft.com/en-us/library/ms162773.aspx?f=255&MSPPError=-2147217396

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.

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s