SQL Mass Insert

It is quicker to insert into a heap table (table with no indexes) or into a table with a clustered index if I know 99% of the time my inserts can be sequential to the column the clustered index is on.

Thanks,
dthansenAsked:
Who is Participating?
 
dqmqCommented:
>This table is functioning as a temporary queue for another system.
Have you considered using a queue.  Service Broker is very much optimized for such things.  

>I do believe in primary keys. In this particular situation though, there is nothing unique in the data itself and duplicate records are permitted.

Then you best get something unique in there, lest the copy/delete may be spending some of its leisure time perplexed and nasty. Exceptions very rare. :>).

As soon as you add a key, you add an index.  As soon as you add an index, the balance shifts in favor of a clustered index on an ever-increasing key.  All said though, with that much volume it's probably worth the effort to benchmark both ways and let the solution prove itself.



0
 
JestersGrindCommented:
According to this MS article, inserting into a heap is slower.

http://support.microsoft.com/kb/297861

Greg

0
 
dqmqCommented:
Not a simple question, really...the answer may very well depend on things like table size, # rows being inserted at one time, and number of processors.   But, I expect a heap with no indexes (assuming that's what you really mean) would be faster since there is no index structure to maintain.

Academic question, I hope.  You do believe in primary keys, right?  
0
 
dqmqCommented:
In some environments, you can get better performance by loading into un-indexed heaps and building the indexes (clustered or otherwise) in a subsequent step.    
0
 
dthansenAuthor Commented:
The table has only 4 columns, all of them integer. We will be inserting 500,000 rows at a time. The server has 2 quad-core process and 16GB RAM.

This table is functioning as a temporary queue for another system. Basically, we dump records into it and this other process comes along as copies/deletes the records at its leisure. This table may contain as many as 30,000,000 rows before this other process picks up the records.

I do believe in primary keys. In this particular situation though, there is nothing unique in the data itself and duplicate records are permitted.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.