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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.