select count(1) chi_rows from chi
where chi_company_id is null
or chi_parent_id is null
or chi_child_id is null
or chi_next_version_id is null;

select count(1) chi_rows from (
select chi_company_id cmp, chi_parent_id prn, chi_child_id chd, chi_next_version_id nxt, count(1) from chi
group by chi_company_id, chi_parent_id, chi_child_id, chi_next_version_id
having count(1) > 1) as a;

select count(1) cat_rows from cat
where cat_id is null
or cat_next_version_id is null
or cat_container_id is null
or cat_company_id is null;

select count(1) cat_rows from (
select cat_id, cat_next_version_id, cat_container_id, cat_company_id, count(1) from cat
group by cat_id, cat_next_version_id, cat_container_id, cat_company_id
having count(1) > 1) as a;

select count(1) itm_rows from itm
where itm_id is null
or itm_company_id is null;

select count(1) itm_rows from (
select itm_id, itm_next_version_id, itm_container_id, itm_company_id, count(1) from itm
group by itm_id, itm_next_version_id, itm_container_id, itm_company_id
having count(1) > 1) as a;

select count(1) icm_rows from icm
where icm_item_id is null
or icm_next_version_id is null
or icm_cat_tree_id is null
or icm_category_id is null
or icm_company_id is null;

select count(1) icm_rows from (
select icm_item_id, icm_next_version_id, icm_cat_tree_id, icm_category_id, icm_company_id, count(1) from icm
group by icm_item_id, icm_next_version_id, icm_cat_tree_id, icm_category_id, icm_company_id
having count(1) > 1) as a;

select count(1) cfp_rows from cfp
where cfp_full_path is null
or cfp_full_path_type is null 
or cfp_next_version_id is null
or cfp_cat_tree_id is null;

select count(1) cfp_rows from (
select cfp_full_path, cfp_full_path_type, cfp_next_version_id, cfp_cat_tree_id, count(1) from cfp
group by cfp_full_path, cfp_full_path_type, cfp_next_version_id, cfp_cat_tree_id
having count(1) > 1) as a;

select count(1) noh_rows from noh
where noh_spec_id is null
or noh_next_version_id is null
or noh_order is null
or noh_company_id is null;

select count(1) noh_rows from (
select noh_spec_id, noh_next_version_id, noh_order, noh_company_id, count(1) from noh
group by noh_spec_id, noh_next_version_id, noh_order, noh_company_id
having count(1) > 1) as a;

select count(1) nod_rows from nod
where nod_id is null
or nod_next_version_id is null
or nod_spec_id is null
or nod_company_id is null;

select count(1) nod_rows from (
select nod_id, nod_next_version_id, nod_spec_id, nod_company_id, count(1) from nod
group by nod_id, nod_next_version_id, nod_spec_id, nod_company_id
having count(1) > 1) as a;

select count(1) wfe_rows from wfe
where wfe_id is null;

select count(1) wfe_rows from (
select wfe_id, count(1) from wfe
group by wfe_id
having count(1) > 1) as a;
---

select count(1) wee_fk_chk from wee
where not exists 
(select 1 from wfe
where wfe_id = wee_event_id);
