How to Run a Very Large SQL Script Without Opening It in SSMS


Sometimes, you get a SQL script file so large that SQL Server Management Studio (SSMS) or regular text editors can't even open it.
This can happen when the file is hundreds of MBs or even several GBs, often containing bulk data inserts, schema creation, or migration scripts.
In this article, I’ll show you why this happens, and how you can run such scripts without loading them into memory.
Why SSMS and Notepad Fail
SSMS tries to load the entire file into memory before executing it.
Editors like Notepad or even Notepad++ will either crash or freeze if the file is too large.
Large files (1GB+) consume a lot of RAM during parsing, making it impossible to edit or even view them on normal machines.
Better Ways to Handle Large SQL Scripts
1. Use sqlcmd
to Run the File Directly
sqlcmd
is a command-line utility provided by SQL Server that can execute SQL files without loading them fully into an editor.
Example:
sqlcmd -S .\SQL2022 -d master -i "C:\Path\To\BigScript.sql"
Explanation:
-S .\SQL2022
→ Connect to the local SQL Server instance namedSQL2022
.-d master
→ Start execution in themaster
database (safe choice for scripts that create databases).-i
→ Path to your SQL file.
If you use SQL authentication:
sqlcmd -S .\SQL2022 -U sa -P YourPassword -d master -i "C:\Path\To\BigScript.sql"
2. Store the Output in a Log File
You can save execution results for later review:
sqlcmd -S .\SQL2022 -d master -i "C:\Path\To\BigScript.sql" -o "C:\Path\ExecutionLog.txt"
Now you have a clean record of what happened during the execution.
3. Split the File into Smaller Parts
If you need to edit the script:
Use tools like GSplit, EmEditor, or a PowerShell script to break the file into smaller chunks.
Example PowerShell:
Get-Content "C:\Path\BigScript.sql" -ReadCount 1000 | % {
$i++
$_ | Out-File "C:\Path\Part_$i.sql"
}
4. Use a Large File-Friendly Editor
If viewing or editing is absolutely necessary:
Final Thoughts
When dealing with massive SQL scripts, the goal is execution without full loading.
The sqlcmd
tool is perfect for this job — lightweight, fast, and does not require opening the file in SSMS.
#SQLServer #DatabaseTips #DevOps #BigData #sqlcmd #Performance
I’m Morteza Jangjoo and “Explaining things I wish someone had explained to me”
Subscribe to my newsletter
Read articles from Morteza Jangjoo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
