Three foreign keys connect a small order schema:
- •
ri_order_lines.order_id → ri_orders.order_id - •
ri_order_lines.product_id → ri_products.product_id - •
ri_orders.customer_id → ri_customers.customer_id
The warehouse doesn't enforce them, so check them. For each foreign-key column, report how many child rows it has, how many have a NULL key, and how many are orphans: a non-NULL key that matches no row in the parent table. A NULL key is a different problem (the value was never filled in), so it is never counted as an orphan.
Return all three foreign keys, even one with no problems.
Columns: fk_column (exactly 'ri_order_lines.order_id', 'ri_order_lines.product_id' or 'ri_orders.customer_id'), child_rows, null_fk_rows, orphan_rows. Sort by fk_column.