What is the fastest way for INSERT to load data from one table to another? (SQL Server 2005)

I'm basically trying to copy data from a table in one database in SQL Server 2005 to another table with the same structure (but with a large number of indexes) in another database in the same instance of SQL Server.

My current approach is the obvious INSERT / SELECT:

set identity_insert TargetDBName.dbo.TableName on

insert into TargetDBName.dbo.TableName ([FieldsList])
  select [FieldsList] from  TargetDBName.dbo.TableName    

set identity_insert SourceDBName.dbo.TableName off

What is required is approximately forever (1 hour for 10 million records, while it took 20 minutes to do this from a table with indexes without them).

What is the best way to do this?

Thanks!

+3
source share
2 answers

, , , , . ,

----Disable Index
ALTER INDEX [*INDEX_NAME*] ON *TABLE_NAME* DISABLE
GO
----Enable Index
ALTER INDEX [*INDEX_NAME*] ON *TABLE_NAME* REBUILD
GO
+4
+1

Source: https://habr.com/ru/post/1709881/


All Articles