Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / July 2008

Tip: Looking for answers? Try searching our database.

Insert with Openrowset  takes a long time

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Danny Ni - 23 Jul 2008 07:00 GMT
Hi,

I use the following command to insert data into a table from a text file:

INSERT ... SELECT * FROM OPENROWSET(BULK...)

The table has 4 indexes and it take about 2 hours if the text file has 2
million rows. However if the table has no indexes, inserting the same text
file takes about 5 minutes. Someone suggests me to drop the indexes before
insert, then recreate them after. Is this the right thing to do? The text
files I deal with are all about the same size.

TIA
Uri Dimant - 23 Jul 2008 07:29 GMT
Danny
Yes , it is good practice (in general) to drop all indexes before inserting
a huge amount of data
Have you also tried

SELECT * INTO #tmp FROM FROM OPENROWSET(BULK...), how long does it take?

> Hi,
>
[quoted text clipped - 9 lines]
>
> TIA
Eric Isaacs - 23 Jul 2008 07:42 GMT
Inserts will always take longer when there are indexes involved, so
the idea of dropping the indexes before the bulk insert is totally
valid.  I've used this technique myself many times. As you get more
and more data, recreating the indexes will take more and more time,
however.  It might be the case that inserting the data takes 5
minutes, but recreating the indexes takes a lot more time.

Select's executed against the table when the indexes are dropped will
take a long time, so there is another cost to removing those indexes
that you need to be aware of.  If the table isn't being used for
reading during those bulk inserts, then do consider dropping those
indexes.

Make sure that all those indexes are needed and used regularly.
Reducing the number of indexes could help in either case, but could
increase the time required to select data from those tables.

-Eric Isaacs
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.