Importing large .sql files to SQL Server

When working with large SQL Server dump files, GUI tools like SSMS or Azure Data Studio can become slow, freeze or fail entirely.

In those cases, importing the script from the command line with sqlcmd is usually more reliable.

Before running the import, make sure sqlcmd is available from your terminal:

sqlcmd -?
sqlcmd -S 192.168.1.116,1433 -d WebApp -l 30 -U username -P password -C -i WebApp_202605281822.sql
  • -S specifies the SQL Server host and port
  • -d selects the target database
  • -l 30 sets the login timeout to 30 seconds
  • -U is the SQL Server username
  • -P is the password
  • -C trusts the server certificate
  • -i provides the input .sql file to execute

Add output logging

For larger imports, I usually write the output to a log file:

sqlcmd -S 192.168.1.116,1433 -d WebApp -l 30 -U username -C -i WebApp_202605281822.sql -o import.log

The -o import.log option writes the output to a file, which makes it easier to review errors after a long-running import.

Safer password

For local throwaway environments this may be fine, but avoid putting production credentials directly in shell history.

If you omit the -P, sqlcmd will prompt for the password.