Which is faster for millions of records: Permanent Table or Temp Tables?
I have to use it only for 15 million records. After processing is complete, we delete t
It depends.
Temp tables are stored in the tempdb
database, which may or may not be on a different drive than your actual database. So a lot depends on a) the speed of those drives and b) which databases/files are on the same drive.
(for example, your actual database will be faster if database files and log files are on different physical drives)
If you use an availability solution like Database Mirroring, temp tables are probably faster:
At work, we are using synchronous Database Mirroring, which means that if we write to our database, the data is immediately written to the mirror server as well, and the main server waits for the mirror's confirmation before returning to the caller(!).
So if you insert 15 million records into a table, process them (probably involving some big updates on all of them) and delete them afterwards, SQL Server has to propagate all these changes immediately over the network to the mirror server.
On the other hand, doing this in a temp table will stay local on the server, in the tempdb
database.