SQL Server, How to do a fast massive insert
Hi Guys! Today a light post to read to start the week! An easy and practical trick related to massive insertions. Do we insert indexes before or after populating a table? Enjoy the reading! A massive insert Suppose you have to insert a large number of rows into a table that doesn't exist yet. This table will have a clustered index let's say on the ID field. Let's start with a question: When do we create our clustered index? I have seen many times procedures that created the table and put the clustered index on it, then mass insertion took place. Let's do our test! Let's create our table with the command: CREATE TABLE [dbo].[Movements]( [Id] [int] [Qty] [float] NULL, [Price] [float] NULL ) ON [PRIMARY] Right now our table has no indexes so it's called a heap table . Let's create our clustered index: CREATE CLUSTERED INDEX CI_MOVEMENTS_ID ON Movements(ID) Now we insert 10 million rows with this command: INSERT INTO Movement...