Solved

how to run a large SQL Query?   "Insufficient memory"

Posted on 2013-06-05
9
536 Views
Last Modified: 2013-06-05
I have a 50MB .sql file.  It loads easily enough into SQL Management studio but I cannot execute it, it spits out an error that there is insufficient memory to parse the script.   Any ideas how I can run this?

SQL 2008
0
Comment
Question by:arthurh88
  • 4
  • 3
  • 2
9 Comments
 
LVL 20

Expert Comment

by:dsacker
ID: 39223741
Just guessing here: If you have embedded INSERT statements, why not change your processing to load your data into a text file and BCP it into SQL.

I've been in DBA and SQL work for over 35 years, and I have yet to write a SQL file that has reached 1MB. What are you doing that must make this 50MB?
0
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 39223746
Couple of things that come to mind..

Split the script into "bite-sized" pieces.

50 MB SQL File?  Are you inserting or creating a ton of data?  It would be recommended to insert or link to the other database if you are using temp tables.

SELECT TOP 1 from Table
would trim down the results.

HTH,

Kent
0
 

Author Comment

by:arthurh88
ID: 39223747
yes they are 80,000 insert statements.   i dont know what you mean by BCP it or how to load it into a text file, other than renaming it to .txt....?

it is a ZIP CODE database that i just purchased for 140 bucks.
0
 

Author Comment

by:arthurh88
ID: 39223752
i guess i could cut and paste chunks of it at a time, but PLEASE tell me there is an easier way lol
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 20

Accepted Solution

by:
dsacker earned 500 total points
ID: 39223759
You can split the file into parts, perhaps each 10-15 MB in Size. If you have any CREATE TABLE or statements at the top other than INSERTs, which prep the way, leave them. Then break at 20000 inserts. Then create a 2nd file with the next 20000 inserts, and so on. Execute them one after the other.
0
 
LVL 20

Expert Comment

by:dsacker
ID: 39223769
Did you get your database (that you purchased) by chance just like that SQL, or did they also give you an Access version of it? Because if you got an Access database of it, you can export that right into SQL Server.
0
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 39223784
BCP would be good..  Another way would be OSQL..  For example:

osql -SINSTANCE\SERVERS -Uuser -Ppassword -n -iyour_sql_file.sql -oresult.log -w250

Open in new window


You could do it as part of a DTSX package to import.

HTH,

Kent
0
 
LVL 20

Expert Comment

by:dsacker
ID: 39223794
If OSQL blows, try SQLCMD. Use everything kdyer showed you in his code, just substitute sqlcmd for osql.
0
 

Author Closing Comment

by:arthurh88
ID: 39224172
this is exactly what im doing, and its working...although....i dont like the manual work lol.  but yes, thank you.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now