find_fk_candidates
Find potential foreign key targets for a source column by matching compatible data types and prioritizing primary key candidates, with optional value overlap verification.
Instructions
Discover potential foreign key relationships for a source column.
EXPERIMENTAL — Results are based on common heuristics but have not been battle-tested for utility. They may contain false positives or exclude valid candidates. Use as a starting point for investigation, not as definitive answers.
Searches for target columns that could be the referenced side of a foreign key relationship. Matches by compatible data type. By default only considers target columns that are PK candidates (constraint-backed or structurally unique); set pk_candidates_only=False to broaden the search to all type-compatible columns. Optionally computes value overlap between source and target via SQL INTERSECT.
Args: connection_id: Connection ID from connect_database table_name: Source table name. May be dotted (e.g. 'schema.table' or 'catalog.schema.table') and is resolved against the dialect. column_name: Source column name schema_name: Source schema name. Defaults to the dialect's default schema (e.g. 'dbo' on MSSQL) when omitted. target_schema: Filter targets to this schema. Defaults to source schema. target_tables: Explicit list of target table names target_table_pattern: SQL LIKE pattern for target table names pk_candidates_only: Only compare against PK-candidate columns (default: True) include_overlap: Compute value overlap metrics (default: False) limit: Maximum candidates to return, 0 = no limit (default: 100) catalog: Optional Databricks catalog name. Rejected on non-Databricks dialects (returns an error response). On Databricks the catalog is threaded end-to-end (IDENT-08): the existence check, source-column type reflection, and FK search run against the requested catalog via catalog-scoped reflection (cross-catalog supported — no default-catalog binding required).
Returns: TOON-encoded string with status, source metadata, candidates list, and search info:
status: "success" | "error"
source: object // on success only
column_name: string
table_name: string
schema_name: string
data_type: string
candidates: list // on success only
source_column: string
source_table: string
source_schema: string
source_data_type: string
target_column: string
target_table: string
target_schema: string
target_data_type: string
target_is_primary_key: bool
target_is_unique: bool
target_is_nullable: bool
target_has_index: bool
overlap_count: int // only when include_overlap=True
overlap_percentage: float // only when include_overlap=True
total_found: int // on success only
was_limited: bool // on success only
search_scope: string // on success only
type_incompatible_skipped: int // only when > 0 (type-incompatible targets skipped)
error_message: string // on error onlyError conditions: - Invalid connection_id: returns status "error" with error_message - Table not found: returns status "error" with error_message - Column not found: returns status "error" with error_message - No candidates: returns status "success" with empty candidates list
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| catalog | No | ||
| table_name | Yes | ||
| column_name | Yes | ||
| schema_name | No | ||
| connection_id | Yes | ||
| target_schema | No | ||
| target_tables | No | ||
| include_overlap | No | ||
| pk_candidates_only | No | ||
| target_table_pattern | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |