ALTER TABLE SWITCH (Partition Switch)
ALTER TABLE SWITCH (Partition Switch) is a SQL statement in the DDL Statements category. SQL Server: instantly moves a partition between tables by metadata change only (no data movement). The syntax is ALTER TABLE source SWITCH TO target PARTITION n;. It returns partition switch. A typical example: -- Load data into staging table: CREATE TABLE staging_orders (id INT, order_date DATE, amount DECIMAL) ON [PRIMARY]; -- Switch partition into main partitioned table: ALTER TABLE staging_orders SWITCH TO orders PARTITION 4; -- Instant operation (metadata only) -- No data is physically moved -- Both tables must have identical structure -- Requirements: -- - Same column structure -- - Same indexes -- - Source must be empty or match partition… A close relative is CREATE TABLE, which creates a new table in the database with specified columns, data types, and constraints. A close relative is ALTER TABLE, which modifies an existing table: add/drop columns, modify data types, rename, add/drop constraints.