Database
Tables without primary key(s)
We will go over how we can add primary key(s) to tables that do not have them.
Why do we only replicate tables with primary key(s)?
- We need a way to uniquely identify each row as we use the primary key(s) as the partition key in Kafka to guarantee ordering.
- For us to guarantee data integrity, we perform
MERGE
with the table’s primary key(s)
Scenario #1: I already have pseudo primary key(s)
Let’s use the example of users_no_pk
as our example.
Email is unique, however not the primary key. To make email
unique, we’ll run the following command:
Scenario #2: How do I add primary key(s) to an existing table?
Let’s use this table no_primary_keys
as our example.
To add a primary key, we will now issue this DDL query:
Was this page helpful?