I am planning to keep a table online when data refreshes in background. (I am not planning on partitions at this time). I thought of two approaches.
1. Schema swapping
2. Alter table switch
Could someone suggest me which one is better or are both approaches are same?
I have a table called dbo.T1, needs to be online when data gets updated in dbo.T1
Schema Swapping Implementation:
create schema shadow; create schema swap; create table shadow.T1;
I will refresh data in shadow.T1
ALTER SCHEMA swap TRANSFER dbo.T1;
ALTER SCHEMA dbo TRANSFER shadow.T1;
ALTER SCHEMA shadow TRANSFER swap.T1;
In next load, shadow.T1 table data will be used in refresh as I am using incremental load approach.
- Alter table switch Implementation:
I use the same procedure as above, but I need to make sure target table must be empty.
In the above two approaches, SQL Server is just changing the meta data (I read in some Microsoft docs).
Is there any difference between these two approaches to solve my above problem perspective?