Why is INSERT INTO using so much tempdb and Why is it trying to allocate dbo.sort?
I have a tsql proc that reads a list of tables and copys the contents to identical tables in another database. There seems to be an issue with one really large table (13 gig) that has an identity column and a clustered primary key (sort_in_tempdb = off). The three copy statements are below. The copy takes about 40 minutes and needs more than 8 gig tempdb, otherwise it gives the error below. Without the identity column it copies in about 17 minutes.
questions
1) why is the identity column such a time and resource drain
2) why does the identity column require so much tempdb and a dbo.sort object
3) any suggestions what I can do differently to still copy the table in tsql but be more efficient
SET IDENTITY_INSERT store01copy.dbo.bigtablecopy ON
INSERT INTO store01copy.dbo.bigtablecopy ([idcol],[col2],[lotsofcol])
SELECT [idcol],[col2],[lotsofcol]
FROM store01copy.dbo.bigtablecopy
SET IDENTITY_INSERT store01copy.dbo.bigtablecopy OFF
Error Message: 1105 Could not allocate space for object 'dbo.SORT temporary run storage: 140759625302016' in database 'tempdb' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup