Tuesday, July 3, 2018

How to import large SQL files in database

I recently faced an situation, where i was supplied with a .SQL file which was exported from a large table with some million records. The file was exported from the generate script options of SSMS and  had the insert statements. The size of the file was more than 2GB.

SSMS(SQL Server Management Studio) is not capable enough of handling such big files. It would through one following error:

  • Insufficient memory to continue the execution of the program.
  • or SSMS would simply reject the request to open the file.

SQLCMD is the life saver here. We could use SQL command line utility to execute the T-SQL commands. It is pretty simple to use as detailed below:

  1. Open the Command prompt with the administrator privileges.
  2. Execute the following command.


 sqlcmd -S SQLSERVER\InstanceName -i "F:\File.sql"


The difference: SSMS uses the .Net framework for execution where as the command line uses ODBC driver.

No comments:

Post a Comment

If you liked the post, please share it.
Subscribe to your email and receive new articles on your email