# Local Unique Index on Partitioned Table Example - Error 1503

+ TiDB creates **local** index for each partition
+ To ensure the uniqueness, the column list for **both** the unique index and primary key index must contain partition keys

```8
tidb> CREATE TABLE t (
 -> A INT,
 -> B INT,
 -> ~!@UNIQUE KEY (B)@!~
 -> )
 -> ~!@PARTITION BY RANGE (A)@!~ (
 -> PARTITION p0 VALUES LESS THAN (10),
 -> PARTITION p1 VALUES LESS THAN (20),
 -> PARTITION p2 VALUES LESS THAN (MAXVALUE)
 -> );
~!@ERROR 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function@!~

tidb> CREATE TABLE t (
 -> A INT,
 -> B INT,
 -> ~!@UNIQUE KEY (A, B)@!~
 -> )
 -> ~!@PARTITION BY RANGE (A)@!~ (
 -> PARTITION p0 VALUES LESS THAN (10),
 -> PARTITION p1 VALUES LESS THAN (20),
 -> PARTITION p2 VALUES LESS THAN (MAXVALUE)
 -> );
Query OK, 0 rows affected (0.55 sec)
```

------------------------------------------------------------------------------
For example:

```
tidb> CREATE TABLE t (
 -> A INT,
 -> B INT,
 -> UNIQUE KEY (B)
 -> )
 -> PARTITION BY RANGE (A) (
 -> PARTITION p0 VALUES LESS THAN (10),
 -> PARTITION p1 VALUES LESS THAN (20),
 -> PARTITION p2 VALUES LESS THAN (MAXVALUE)
 -> );
ERROR 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function
```

Because index entries are built on different partitions, the uniqueness of the index can not be guaranteed. So, In TiDB, these indexes are not allowed.

Every unique key on the table should include all columns in the partitioning expression, including the primary key, as it inherently serves as a unique key.The follow is valid:

```
tidb> CREATE TABLE t (
 -> A int,
 -> B int,
 -> UNIQUE KEY (A, B)
 -> )
 -> PARTITION BY RANGE (A) (
 -> PARTITION p0 VALUES LESS THAN (10),
 -> PARTITION p1 VALUES LESS THAN (20),
 -> PARTITION p2 VALUES LESS THAN (maxvalue)
 -> );
Query OK, 0 rows affected (0.55 sec)
```

More detail: https://docs.pingcap.com/tidb/stable/partitioned-table#partitioning-keys-primary-keys-and-unique-keys