# Partition Management - Exchanging Partitions

+ Exchange a partition with a non-partitioned table
+ All rows in the non-partitioned table must adhere to the partition definition

```12
ALTER TABLE users_partitioned ~!@EXCHANGE PARTITION@!~
  p0 ~!@WITH TABLE@!~ users_non_partitioned;
```
------------------------------------------------------------------------------
The `EXCHANGE PARTITION` operation involves swapping a partition with a non-partitioned table, for example:

```
tidb> CREATE TABLE users_non_partitioned (
 -> sub_id INT NOT NULL,
 -> firstname VARCHAR(25) NOT NULL,
 -> lastname VARCHAR(25) NOT NULL,
 -> journalid INT NOT NULL,
 -> joined DATE NOT NULL
 -> );
Query OK, 0 rows affected (0.53 sec)

tidb> INSERT INTO users_non_partitioned VALUES(1, 'Jack','Smith', 5001, '1998-12-10 14:10:22');

tidb> CREATE TABLE users_partitioned (
 -> sub_id INT NOT NULL,
 -> firstname VARCHAR(25) NOT NULL,
 -> lastname VARCHAR(25) NOT NULL,
 -> journalid INT NOT NULL,
 -> joined DATE NOT NULL
 -> )
 -> PARTITION BY RANGE( YEAR(joined) ) (
 -> PARTITION p0 VALUES LESS THAN (2000),
 -> PARTITION p1 VALUES LESS THAN (2010),
 -> PARTITION p2 VALUES LESS THAN (2020),
 -> PARTITION p3 VALUES LESS THAN (2030)
 -> );
Query OK, 0 rows affected (0.53 sec)

tidb> ALTER TABLE users_partitioned EXCHANGE PARTITION p0 WITH TABLE users_non_partitioned;
Query OK, 0 rows affected, 1 warning (0.52 sec)

tidb> SELECT * FROM users_partitioned;
+--------+-----------+----------+-----------+------------+
| sub_id | firstname | lastname | journalid | joined     |
+--------+-----------+----------+-----------+------------+
| 1      | Jack      | Smith    | 5001      | 1998-12-10 |
+--------+-----------+----------+-----------+------------+
1 row in set, 1 warning (0.02 sec)
```

Please note that TiDB has specific features that may impact the `EXCHANGE PARTITION` operation. When the table structure includes these features, you must ensure that the operation meets the necessary prerequisites. Furthermore, ensure consistent definition of these specific features for both partitioned and non-partitioned tables. These specific features include the following:

1. Placement Rules in SQL: placement policies are the same.

2. TiFlash: the numbers of TiFlash replicas are the same.

3. Clustered indexes: partitioned and non-partitioned tables are both `CLUSTERED`, or both `NONCLUSTERED`.

4. TiCDC: TiCDC replicates the `EXCHANGE PARTITION` operation when both partitioned and non-partitioned tables have primary keys or unique keys. Otherwise, TiCDC will not replicate the operation.

5. TiDB Lightning and Backup & Restore (BR): Do not perform the `EXCHANGE PARTITION` operation during TiDB Lightning import or Backup & Restore (BR) restoration.