# Defining a primary key

A primary key dimension is a field which contains keys unique for each record. When you add dimensions to your Qommentary Writeback table, you will need to select one dimension to be used as the **primary key**.

To select a dimension to be used as a primary key, please follow these steps:

1\. Add a dimension to your table

<div align="left"><img src="https://1677646431-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M43RhGzV8Plu0tfknia%2F-MYecTCmLO4suqN0VUqZ%2F-MYeeJZ3xS47WBkDNBpE%2Fimage.png?alt=media&#x26;token=c5170220-0e5a-4ef6-92b0-0e25fbf43250" alt=""></div>

2\. Expand the dimension's properties\
3\. Click on the switch control to select dimension as **Primary key dimension**

<div align="left"><img src="https://1677646431-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M43RhGzV8Plu0tfknia%2F-MYecTCmLO4suqN0VUqZ%2F-MYeelqUCcGxzmXBasiN%2Fimage.png?alt=media&#x26;token=51aa6f86-ef88-4cc3-a015-3c987c80e758" alt=""></div>

{% hint style="warning" %}
Be aware of any additional dimensions added which could split the primary key dimension forcing it to display duplicated values - thus breaking the primary key purpose.&#x20;

In that case, consider creating a **composite key**.
{% endhint %}

### Using a single dimension

When the dimension chosen to act as a primary key displays unique records in the table, then selecting a single dimension is sufficient.

Example:\
&#x20;<img src="https://1677646431-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M43RhGzV8Plu0tfknia%2F-MYefkTl0rEUw3HGf9lT%2F-MYegToQu6PukfcHUrMh%2Fimage.png?alt=media&#x26;token=3ee7d00a-be7a-4d71-8af9-ffd77e6d8705" alt="" data-size="original">&#x20;

### Using a composite dimension

When a single dimension cannot produce unique records, then a composite dimension must be created.&#x20;

Example:\
&#x20;<img src="https://1677646431-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M43RhGzV8Plu0tfknia%2F-MYefkTl0rEUw3HGf9lT%2F-MYehMDwnTz-mHNfCLsw%2Fimage.png?alt=media&#x26;token=7ece3283-e396-41cb-b38b-23e3da56e5e7" alt="" data-size="original">&#x20;

{% hint style="info" %}
You may hide the column if you do not wish to display it in your table.
{% endhint %}
