简体   繁体   中英

SQL Server : large data import with clustered index

Performance-wise, does a clustered index help or not when bulk inserting hundreds of millions of rows in a table?

LE: after the INSERTs I have to put the database into production so I will have to create the one or more indexes.

A clustered index specifies that the data is ordered on the data pages.

When you are inserting data, the new data has to be sorted and compared to existing values. This is going to incur overhead.

The one exception is when you have an identity column -- that is being generated during the insert. Then the database knows that the new data goes "at the end" of the table.

Indexes are meant for speeding up retrieval ( SELECT ) of rows. They only have anti-effect with respect to INSERT or DELETE or UPDATE . And, in your case, if INSERT is the predominant operation to be performed in your system, don't go for indexes at all. Even in your Production system, assess the ratio between retrieval operations and insert/update operations and if it turns out to be that the retrieval operation is going to be dominant, then you can think of indexes.

Note: Whenever we define a Primary Key on a table, a basic index structure is already created for that table. So, without any specific need for retrieval optimization, there is no actual need to design and implement indexes.

You can know more here: https://www.geeksforgeeks.org/sql-indexes/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM