How Does it Work? If I have tables with the identical data structure that use the same partition scheme, I can move data using partition switching. Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 Contains Data Empty Partition
How Does it Work? I can load and modify data in a staging table… Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 Contains Data Empty Partition
How Does it Work? …issue a switch command… Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 ALTER TABLE [Table_Staging] SWITCH PARTITION 7 to [Table] PARTITION 7; Contains Data Empty Partition
How Does it Work? …and the data will be ‘moved’ instantly. Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 Contains Data Empty Partition
How Does it Work. I can only switch data into an empty partition How Does it Work? I can only switch data into an empty partition. If I stage data that I want to replace existing data with, I need to make room. Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 Contains Data Empty Partition
How Does it Work? I can switch data out of my primary table… Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 ALTER TABLE [Table] SWITCH PARTITION 1 to [Table_Delete] PARTITION 1; SWITCH PARTITION 2 to [Table_Delete] PARTITION 2; Contains Data Empty Partition
How Does it Work? …switch the data from staging to my primary table… Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 ALTER TABLE [Table_Staging] SWITCH PARTITION 1 to [Table] PARTITION 1; SWITCH PARTITION 2 to [Table] PARTITION 2; Contains Data Empty Partition
How Does it Work? …and then truncate Table_Delete… Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 TRUNCATE TABLE Table_Delete; Contains Data Empty Partition
How Does it Work? …done. Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 Contains Data Empty Partition