Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Drop index and then create index?

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2007-03-17 : 15:38:43
Which way is better?
1) to insert a million records into a table but keep 15 index column
2) drop index, insert a million records and then create index

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-17 : 15:48:22
I would go for option 2.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2007-03-17 : 19:08:21
How many records are in the table to begin with?

rockmoose
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-03-17 : 19:43:32
I would keep the index if it is clustered, AND the data being inserted is pre-sorted in PK order.

Otherwise I would drop the re-create the index.

Might depend on how many MORE records there were in the table to s tart with - as Rocky asks too.

Kristen
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2007-03-18 : 10:26:45
All indexes are simple.
I used command as below:

truncate table mytable
insert...
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2007-03-18 : 19:29:44
Quite often it is good to drop and rebuild the index.
But it does depend...

If the inserted data is ordered - as Kristen asks
Ratio of old/new rows - if the table already has many rows rebuilding the whole index might be more costly than updating it while inserting.

rockmoose
Go to Top of Page
   

- Advertisement -