How to Fix “ALTER TABLE SWITCH statement failed”

If you’re getting error 4939 while trying to switch a partition in SQL Server, it’s probably because you’re trying to switch to a partition that uses a different filegroup.

One of the requirements of switching partitions is that both the source table or partition, and the target table or partition, must be located in the same filegroup.

Example of the Error

Here’s an example of the error:

Msg 4939, Level 16, State 1, Line 1
ALTER TABLE SWITCH statement failed. table 'Test.dbo.OrdersOld' is in filegroup 'OrdersNewFg2' and partition 3 of table 'Test.dbo.OrdersNew' is in filegroup 'OrdersNewFg3'.

In this case, the source table that uses the OrdersNewFg2 filegroup, but the destination table uses OrdersNewFg3.

To resolve this issue, make sure that the source table or partition and the destination table, or partition both use the same filegroup.