edit-icon download-icon

What are primary keys, data partitions, and partition keys

Last Updated: Apr 11, 2018

Primary key

A primary key uniquely identifies a row of record in a table. When creating a table, you must specify the columns that generate the primary key. These specified columns are called primary key columns. A primary key column cannot be set to null. The combination of values of a primary key column must be able to uniquely identify a row. The type of a primary key column cannot be changed once created.

Data partition and partition key

To balance the load of stored data, Table Store automatically divides a table into data partitions. Data is partitioned by the first column of the primary key, which is called data partition key.

Rows that have the same data partition key must belong to the same data partition. This makes sure that Table Store can make consistent changes to data with the same data partition key.

The following figure shows a part of an email table in an email system. Information about the primary key and partition key of the table is as follows:

  • The UserID, ReceiveTime, and FromAddr columns indicate the ID of the email user, receipt time, and sender, respectively. These columns are the primary key columns and can uniquely identify an email. The UserID column is the data partition key.

  • The ToAddr, MailSize, Subject, and Read columns indicate the recipient, email size, email subject, and whether the email is read, respectively. These columns are common columns that store information about the email.

In the following figure, Table Store stores information about users with UserIDs U0001 and U0002 in the same data partition, and information about users with UserIDs U0003 and U0004 in another data partition.

Data partition

Thank you! We've received your feedback.