Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long SQL file runs SQL Server out of memory (22,000 lines)

I have a file of a .sql file that is about 22,000 lines long. It's generated by something else, but basically just contains one update statement per line.

I get this error when I run the file in SQL Server Management Studio.

There is insufficient system memory in resource pool 'internal' to run this query

I think I just need to split this query file up, but I'm not sure the best way to go about it. I could cut the file into 2000 line chunks or something I suppose.

This seems like a simple problem, and I will be doing this often enough I would like to come up with a good solution. Any ideas?

like image 803
BurntToast Avatar asked Apr 20 '12 20:04

BurntToast


People also ask

Why is SQL Server consuming all memory?

SQL Server is designed to use all the memory on the server by default. The reason for this is that SQL Server cache the data in the database in RAM so that it can access the data faster than it could if it needed to read the data from the disk every time a user needed it.

What is the maximum memory for SQL Server?

By default, SQL Server's max memory is 2147483647 – a heck of a lot more than you actually have.

What percentage of memory should SQL Server use?

Memory Management on SQL Server works on the Fill-and-Flush algorithm. The default values do not restrict the memory consumption from growing unless there's a request from the Operating System. The sizing depends on various components of the system—in many cases, setting it between 70% and 80% is a good starting point.


2 Answers

You might want to look into running your script via SQLCMD instead of going through the SSMS GUI interface.

like image 118
Joe Stefanelli Avatar answered Nov 15 '22 21:11

Joe Stefanelli


I had similar problem and running below command in command prompt from blog saved me.

   sqlcmd -S YOURSQLSERVER\INSTANCENAME -i "C:\Your Script.sql"
like image 24
Risky Pathak Avatar answered Nov 15 '22 22:11

Risky Pathak