What's the fastest way to bulk insert a lot of data in SQL Server (C# client)

前端 未结 8 1207
予麋鹿
予麋鹿 2020-11-28 22:39

I am hitting some performance bottlenecks with my C# client inserting bulk data into a SQL Server 2005 database and I\'m looking for ways in which to speed up the process.

8条回答
  •  野性不改
    2020-11-28 23:27

    My guess is that you'll see a dramatic improvement if you change that index to be nonclustered. This leaves you with two options:

    1. Change the index to nonclustered, and leave it as a heap table, without a clustered index
    2. Change the index to nonclustered, but then add a surrogate key (like "id") and make it an identity, primary key, and clustered index

    Either one will speed up your inserts without noticeably slowing down your reads.

    Think about it this way -- right now, you're telling SQL to do a bulk insert, but then you're asking SQL to reorder the entire table every table you add anything. With a nonclustered index, you'll add the records in whatever order they come in, and then build a separate index indicating their desired order.

提交回复
热议问题