Search

Showing posts with label Switch. Show all posts
Showing posts with label Switch. Show all posts

Tuesday, October 11, 2011

Using Switching you can move millions of rows from one table to another in less than a second

Assume that there are two tables table_1 and table_2 which have same structures and table_1 has 10 millions rows and you want to move all rows from table_1 to table_2. The quickest method that I have learnt is to use Partition Switching


ALTER TABLE Table_1 Switch TO Table_2;


The reason why it is fast is that data are not moved actually but SQL Server updates metadata about the location of the data