SELECT CASE WHEN
  (SELECT COUNT(*) FROM (
    SELECT tenant_id FROM dwd_material_readiness
      WHERE tenant_id IS NULL OR tenant_id IN (0,1,1300000000001)
    UNION ALL
    SELECT tenant_id FROM dwd_material_shortage
      WHERE tenant_id IS NULL OR tenant_id IN (0,1,1300000000001)
    UNION ALL
    SELECT tenant_id FROM dwd_order_schedule_trans
      WHERE tenant_id IS NULL OR tenant_id IN (0,1,1300000000001)
    UNION ALL
    SELECT tenant_id FROM dwd_supplier_delivery
      WHERE tenant_id IS NULL OR tenant_id IN (0,1,1300000000001)
    UNION ALL
    SELECT tenant_id FROM dwd_supplier_risk
      WHERE tenant_id IS NULL OR tenant_id IN (0,1,1300000000001)
    UNION ALL
    SELECT tenant_id FROM dwd_supply_demand
      WHERE tenant_id IS NULL OR tenant_id IN (0,1,1300000000001)
    UNION ALL
    SELECT tenant_id FROM ado_s9_kpi_value_l1_day
      WHERE tenant_id IS NULL OR tenant_id IN (0,1,1300000000001)
    UNION ALL
    SELECT tenant_id FROM ado_s9_kpi_value_l2_day
      WHERE tenant_id IS NULL OR tenant_id IN (0,1,1300000000001)
    UNION ALL
    SELECT tenant_id FROM ado_s9_kpi_value_l3_day
      WHERE tenant_id IS NULL OR tenant_id IN (0,1,1300000000001)
    UNION ALL
    SELECT tenant_id FROM ado_s9_kpi_value_l4_day
      WHERE tenant_id IS NULL OR tenant_id IN (0,1,1300000000001)
  ) invalid_rows)=0
  AND
  (SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS
   WHERE CONSTRAINT_SCHEMA=DATABASE()
     AND CONSTRAINT_NAME IN (
       'ck_wp5_valid_tenant_01','ck_wp5_valid_tenant_02',
       'ck_wp5_valid_tenant_03','ck_wp5_valid_tenant_04',
       'ck_wp5_valid_tenant_05','ck_wp5_valid_tenant_06',
       'ck_wp5_valid_tenant_07','ck_wp5_valid_tenant_08',
       'ck_wp5_valid_tenant_09','ck_wp5_valid_tenant_10'))=10
THEN 1 ELSE 0 END AS ok;
