Foreign Keys
Configuration for foreign key relationships between array tables and parent tables, including parent attribute selection, column aliases, and row-level security policy integration.
Overview
Foreign Key metadata configures relationships between array tables and parent tables. Foreign keys link array elements to parent records, enabling joins and maintaining referential integrity.
Foreign Key Configuration
Foreign Key Attribute Name (FOREIGN_KEY_ATTRIBUTE_NAME)
Parent attribute name to use as foreign key
Editable - Select from available parent attributes
Required - Must be valid attribute from parent table/array
Can be from root table, parent array, or previously configured foreign keys
Attributes must be active and included in code generation
Foreign Key Alias Name (FOREIGN_KEY_ALIAS_NAME)
Custom column name alias for foreign key column in array table
Editable - Optional; overrides default naming
Default: Based on parent attribute name and polymorphic version (e.g.,
customer_id_str,order_id_int)Custom: Set for readability (e.g.,
customer_idinstead ofcustomer_id_str)
Include In Security Row Level Policy (INCLUDE_IN_SECURITY_ROW_LEVEL_POLICY)
Boolean for including foreign key in row-level security policy
Editable -
TRUE= included in row access policyRequires Security Policy Integration product tier
Security Row Level Policy Order (SECURITY_ROW_LEVEL_POLICY_ORDER)
Order of foreign key in security policy
Read-only - Set by system; lower numbers evaluated first
Foreign Key Relationships
How foreign keys work:
Parent table contains referenced attribute
Array table contains foreign key column
Foreign key links array elements to parent records
Enables joins:
orders.customer_id = customers.customer_id
Composite foreign keys:
Arrays can have multiple foreign keys
Each links to different parent attribute
All foreign keys included in array table
Example:
order_itemswithorder_idandproduct_id
Nested array foreign keys:
Nested arrays can reference parent array foreign keys
Foreign keys from parent arrays available for selection
Enables multi-level relationships
Example:
order_itemscan usecustomer_idfrom root andorder_idfrom parent array
Foreign Key Configuration Process
Select array - Navigate to Foreign Keys section, select array attribute from dropdown
Add foreign key - Select
FOREIGN_KEY_ATTRIBUTE_NAMEfrom dropdown, optionally setFOREIGN_KEY_ALIAS_NAMEandINCLUDE_IN_SECURITY_ROW_LEVEL_POLICYEdit foreign key - Modify fields as needed
Delete foreign key - Select row, check checkbox, press Delete key
Foreign Key Generation
When foreign keys are configured:
Foreign key columns - Added to array table, named using alias (if provided) or default, data type matches parent attribute
Foreign key values - Populated from parent record, links array element to parent
Join relationships - Based on array relationship configuration (
RELATIONSHIP_TYPE,JOIN_TYPE), supports left outer and inner joins
Best Practices
Foreign key selection:
Select attributes that uniquely identify parent records
Prefer primary key attributes (
IS_PRIMARY_KEY = TRUE)Use stable identifiers (not changing values)
Multiple foreign keys: Use when array relates to multiple parents
Naming:
Use clear, descriptive names for
FOREIGN_KEY_ALIAS_NAMEAvoid technical suffixes when possible (e.g.,
customer_idinstead ofcustomer_id_str)
Security:
Set
INCLUDE_IN_SECURITY_ROW_LEVEL_POLICY = TRUEfor foreign keys with sensitive dataUse for filtering array data by access rights (multi-tenant scenarios)
Common Scenarios
Simple array foreign key:
Select
ordersarrayAdd foreign key: Select
customer_idasFOREIGN_KEY_ATTRIBUTE_NAMESet
FOREIGN_KEY_ALIAS_NAME = 'customer_id'Result:
orderstable includescustomer_idcolumn; enables joins
Nested array foreign keys:
Configure
ordersarray foreign key:customer_idConfigure
order_itemsarray:Foreign Key 1:
customer_id(from root)Foreign Key 2:
order_id(from parent array)
Result:
order_itemstable includes both foreign keys; enables multi-level joins
Composite foreign keys:
Add Foreign Key 1:
order_id(from parent array)Add Foreign Key 2:
product_id(from root or another source)Set appropriate alias names
Result: Both foreign keys included; enables complex joins
Foreign key security:
Set
INCLUDE_IN_SECURITY_ROW_LEVEL_POLICY = TRUECreate row access policy in Snowflake
Policy uses foreign key for filtering array data by access rights
Last updated
Was this helpful?