ALTER TABLE billing_methods ADD CONSTRAINT fk_billing_methods_ctr_id FOREIGN KEY (ctr_id) REFERENCES countries(ctr_id) MATCH FULL;

ALTER TABLE bills ADD CONSTRAINT fk_bills_bmt_id FOREIGN KEY (bmt_id) REFERENCES billing_methods(bmt_id) MATCH FULL;
ALTER TABLE bills ADD CONSTRAINT fk_bills_curr_id FOREIGN KEY (curr_id) REFERENCES currencies(curr_id) MATCH FULL;
ALTER TABLE bills ADD CONSTRAINT fk_bills_cpn_id FOREIGN KEY (cpn_id) REFERENCES companies(cpn_id) MATCH FULL;

ALTER TABLE companies ADD CONSTRAINT fk_companies_ctr_id FOREIGN KEY (ctr_id) REFERENCES countries(ctr_id) MATCH FULL;
ALTER TABLE companies ADD CONSTRAINT fk_companies_ccat_id FOREIGN KEY (ccat_id) REFERENCES companycat(ccat_id) MATCH FULL;
-- ALTER TABLE companies ADD CONSTRAINT fk_companies_pe_id FOREIGN KEY (pe_id) REFERENCES persons(pe_id) MATCH FULL;

ALTER TABLE operations ADD CONSTRAINT fk_operations_pe_id FOREIGN KEY (pe_id) REFERENCES persons(pe_id) MATCH FULL;
ALTER TABLE operations ADD CONSTRAINT fk_operations_prj_id FOREIGN KEY (prj_id) REFERENCES projects(prj_id) MATCH FULL;
ALTER TABLE operations ADD CONSTRAINT fk_operations_opcat_id FOREIGN KEY (opcat_id) REFERENCES operationcat(opcat_id) MATCH FULL;
ALTER TABLE operations ADD CONSTRAINT fk_operations_bill_id FOREIGN KEY (bill_id) REFERENCES bills(bill_id) MATCH FULL;

ALTER TABLE persons ADD CONSTRAINT fk_persons_ctr_id FOREIGN KEY (ctr_id) REFERENCES countries(ctr_id) MATCH FULL;
ALTER TABLE persons ADD CONSTRAINT fk_persons_pecat_id FOREIGN KEY (pecat_id) REFERENCES personcat(pecat_id) MATCH FULL;
ALTER TABLE persons ADD CONSTRAINT fk_persons_cpn_id FOREIGN KEY (cpn_id) REFERENCES companies(cpn_id) MATCH FULL;
ALTER TABLE persons ADD CONSTRAINT fk_persons_jcat_id FOREIGN KEY (jcat_id) REFERENCES jobcat(jcat_id) MATCH FULL;
-- ALTER TABLE persons ADD CONSTRAINT fk_persons_pe_pe_id FOREIGN KEY (pe_pe_id) REFERENCES persons(pe_id) MATCH FULL;

ALTER TABLE projects ADD CONSTRAINT fk_projects_cpn_id FOREIGN KEY (cpn_id) REFERENCES companies(cpn_id) MATCH FULL;
ALTER TABLE projects ADD CONSTRAINT fk_projects_cpn_id_issuebill FOREIGN KEY (cpn_id_issuebill) REFERENCES companies(cpn_id) MATCH FULL;
ALTER TABLE projects ADD CONSTRAINT fk_projects_jcat_id FOREIGN KEY (prjcat_id) REFERENCES projectcat(prjcat_id) MATCH FULL;
-- ALTER TABLE projects ADD CONSTRAINT fk_projects_pe_id FOREIGN KEY (pe_id) REFERENCES persons(pe_id) MATCH FULL;
ALTER TABLE projects ADD CONSTRAINT fk_projects_prjstat_id FOREIGN KEY (prj_status) REFERENCES projectstatus(prjstat_id) MATCH FULL;
ALTER TABLE projects ADD CONSTRAINT fk_projects_prj_prj_id FOREIGN KEY (prj_prj_id) REFERENCES projects(prj_id) MATCH FULL;
ALTER TABLE projects ADD CONSTRAINT fk_projects_quot_id FOREIGN KEY (quot_id) REFERENCES quotations(quot_id) MATCH FULL;
ALTER TABLE projects ADD CONSTRAINT fk_projects_prj_manager_pe_id FOREIGN KEY (prj_manager_pe_id) REFERENCES persons(pe_id) MATCH FULL;

ALTER TABLE project_members ADD CONSTRAINT fk_project_members_prj_id FOREIGN KEY (prj_id) REFERENCES projects(prj_id) MATCH FULL;
ALTER TABLE project_members ADD CONSTRAINT fk_project_members_jcat_id FOREIGN KEY (jcat_id) REFERENCES jobcat(jcat_id) MATCH FULL;
ALTER TABLE project_members ADD CONSTRAINT fk_project_members_pe_id FOREIGN KEY (pe_id) REFERENCES persons(pe_id) MATCH FULL;

ALTER TABLE quotations ADD CONSTRAINT fk_quotations_bmt_id FOREIGN KEY (bmt_id) REFERENCES billing_methods(bmt_id) MATCH FULL;
ALTER TABLE quotations ADD CONSTRAINT fk_quotations_curr_id FOREIGN KEY (curr_id) REFERENCES currencies(curr_id) MATCH FULL;
ALTER TABLE quotations ADD CONSTRAINT fk_quotations_cpn_id FOREIGN KEY (cpn_id) REFERENCES companies(cpn_id) MATCH FULL;

ALTER TABLE users ADD CONSTRAINT fk_users_pe_id FOREIGN KEY (pe_id) REFERENCES persons(pe_id) MATCH FULL;
ALTER TABLE users ADD CONSTRAINT fk_users_lng_id FOREIGN KEY (lng_id) REFERENCES languages(lng_id) MATCH FULL;

ALTER TABLE userconfig ADD CONSTRAINT fk_userconfig_cfg_id FOREIGN KEY (cfg_id) REFERENCES config(cfg_id) MATCH FULL;
ALTER TABLE userconfig ADD CONSTRAINT fk_userconfig_usr_id FOREIGN KEY (usr_id) REFERENCES users(usr_id) MATCH FULL;

ALTER TABLE expenses ADD CONSTRAINT fk_expenses_pe_id FOREIGN KEY (pe_id) REFERENCES persons(pe_id) MATCH FULL;
ALTER TABLE expenses ADD CONSTRAINT fk_expenses_prj_id FOREIGN KEY (prj_id) REFERENCES projects(prj_id) MATCH FULL;
ALTER TABLE expenses ADD CONSTRAINT fk_expenses_curr_id FOREIGN KEY (curr_id) REFERENCES currencies(curr_id) MATCH FULL;
ALTER TABLE expenses ADD CONSTRAINT fk_expenses_curr_id_foreign FOREIGN KEY (curr_id_foreign) REFERENCES currencies(curr_id) MATCH FULL;
ALTER TABLE expenses ADD CONSTRAINT fk_expenses_bill_id FOREIGN KEY (bill_id) REFERENCES bills(bill_id) MATCH FULL;

ALTER TABLE lineitems ADD CONSTRAINT fk_lineitems_bill_id FOREIGN KEY (bill_id) REFERENCES bills(bill_id) MATCH FULL;
ALTER TABLE lineitems ADD CONSTRAINT fk_lineitems_quot_id FOREIGN KEY (quot_id) REFERENCES quotations(quot_id) MATCH FULL;
ALTER TABLE lineitems ADD CONSTRAINT fk_lineitems_op_id FOREIGN KEY (op_id) REFERENCES operations(op_id) MATCH FULL;

ALTER TABLE files ADD CONSTRAINT fk_files_pe_id FOREIGN KEY (pe_id) REFERENCES persons(pe_id) MATCH FULL;

ALTER TABLE products ADD CONSTRAINT fk_products_prcat_id FOREIGN KEY (prcat_id) REFERENCES productcat(prcat_id) MATCH FULL;

ALTER TABLE material ADD CONSTRAINT fk_material_prod_id FOREIGN KEY (prod_id) REFERENCES products(prod_id) MATCH FULL;
ALTER TABLE material ADD CONSTRAINT fk_material_pe_id FOREIGN KEY (pe_id) REFERENCES persons(pe_id) MATCH FULL;
ALTER TABLE material ADD CONSTRAINT fk_material_prj_id FOREIGN KEY (prj_id) REFERENCES projects(prj_id) MATCH FULL;
ALTER TABLE material ADD CONSTRAINT fk_material_bill_id FOREIGN KEY (bill_id) REFERENCES bills(bill_id) MATCH FULL;

ALTER TABLE lineitems ADD CONSTRAINT fk_lineitems_mat_id FOREIGN KEY (mat_id) REFERENCES material(mat_id) MATCH FULL;

ALTER TABLE projects_hourlyrates ADD CONSTRAINT fk_projects_hourlyrates_pe_id_lastmod FOREIGN KEY (pe_id_lastmod) REFERENCES persons(pe_id) MATCH FULL;
ALTER TABLE projects_hourlyrates ADD CONSTRAINT fk_projects_hourlyrates_pe_id FOREIGN KEY (pe_id) REFERENCES persons(pe_id) MATCH FULL;
ALTER TABLE projects_hourlyrates ADD CONSTRAINT fk_projects_hourlyrates_prj_id FOREIGN KEY (prj_id) REFERENCES projects(prj_id) MATCH FULL;
ALTER TABLE projects_hourlyrates ADD CONSTRAINT fk_projects_hourlyrates_opcat_id FOREIGN KEY (opcat_id) REFERENCES operationcat(opcat_id) MATCH FULL;

ALTER TABLE recurrbills ADD CONSTRAINT fk_recurrbills_bill_id FOREIGN KEY (bill_id) REFERENCES bills(bill_id) MATCH FULL;
ALTER TABLE bills ADD CONSTRAINT fk_bills_rbill_id FOREIGN KEY (rbill_id) REFERENCES recurrbills(rbill_id) MATCH FULL;
