Identify Primary Key for Each Table (MySQL, MSSQL,...
# ask-ai
n
Identify Primary Key for Each Table (MySQL, MSSQL, PostgreSQL, MongoDB)
k
To identify the primary key for each table in Airbyte, you typically use the "Primary key" field in the connector configuration. This field specifies how to uniquely identify a record, which is crucial for downstream de-duplication (e.g., in incremental sync - Append + Deduped sync mode). The primary key can be a single field (like an
id
) or a combination of fields if no single unique field exists. This approach is consistent across different source types, including MySQL, MSSQL, PostgreSQL, and MongoDB, when configuring connectors in Airbyte. How to Specify the Primary Key: - Single Field Example: If your table has a unique
id
field, set the primary key to
id
. - Composite Key Example: If uniqueness is guaranteed by a combination of fields (e.g.,
code
and
type
), set the primary key to
code, type
. Example JSON for Composite Key:
Copy code
json "primary_key": ["code", "type"]
This configuration is set in the Airbyte Connector Builder UI or in the connector's configuration JSON. The process is the same regardless of the underlying database (MySQL, MSSQL, PostgreSQL, MongoDB), as Airbyte abstracts the primary key concept for de-duplication and record identification purposes. References: - The documentation provides examples and guidance on setting the primary key for record processing in Airbyte connectors, including cases where a composite key is needed if no single unique field exists [Record Processing: Meta data](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/record-processing#meta-data). Note: The knowledge sources do not provide database-specific SQL queries or commands for discovering primary keys directly from MySQL, MSSQL, PostgreSQL, or MongoDB. They focus on how to configure primary keys within Airbyte for connector and sync purposes. If you need to programmatically discover primary keys from the source databases themselves, that information is not covered in the provided documentation.