if exists (select 1 from sysobjects where name = 'tu_C_customer')
    drop trigger tu_C_customer;

create trigger tu_C_customer on C_customer for update as
begin
    set nocount on
    update C_customer set this.version = this.version + 1
        from C_customer this, inserted
        where this.c_id = inserted.c_id
end;

if exists (select 1 from sysobjects where name = 'tu_C_customerinventory')
    drop trigger tu_C_customerinventory;

create trigger tu_C_customerinventory on C_customerinventory for update as
begin
    set nocount on
    update C_customerinventory set this.version = this.version + 1
        from C_customerinventory this, inserted
        where this.ci_id = inserted.ci_id
end;

if exists (select 1 from sysobjects where name = 'tu_C_parts')
    drop trigger tu_C_parts;

create trigger tu_C_parts on C_parts for update as
begin
    set nocount on
    update C_parts set this.version = this.version + 1
        from C_parts this, inserted
        where this.p_id = inserted.p_id
end;

if exists (select 1 from sysobjects where name = 'tu_C_site')
    drop trigger tu_C_site;

create trigger tu_C_site on C_site for update as
begin
    set nocount on
    update C_site set this.version = this.version + 1
        from C_site this, inserted
        where this.site_id = inserted.site_id
end;

if exists (select 1 from sysobjects where name = 'tu_C_supplier')
    drop trigger tu_C_supplier;

create trigger tu_C_supplier on C_supplier for update as
begin
    set nocount on
    update C_supplier set this.version = this.version + 1
        from C_supplier this, inserted
        where this.supp_id = inserted.supp_id
end;

if exists (select 1 from sysobjects where name = 'tu_M_bom')
    drop trigger tu_M_bom;

create trigger tu_M_bom on M_bom for update as
begin
    set nocount on
    update M_bom set this.version = this.version + 1
        from M_bom this, inserted
        where this.b_assembly_id = inserted.b_assembly_id and this.b_line_no = inserted.b_line_no and this.b_comp_id = inserted.b_comp_id
end;

if exists (select 1 from sysobjects where name = 'tu_M_largeorder')
    drop trigger tu_M_largeorder;

create trigger tu_M_largeorder on M_largeorder for update as
begin
    set nocount on
    update M_largeorder set this.version = this.version + 1
        from M_largeorder this, inserted
        where this.lo_id = inserted.lo_id
end;

if exists (select 1 from sysobjects where name = 'tu_M_parts')
    drop trigger tu_M_parts;

create trigger tu_M_parts on M_parts for update as
begin
    set nocount on
    update M_parts set this.version = this.version + 1
        from M_parts this, inserted
        where this.p_id = inserted.p_id
end;

if exists (select 1 from sysobjects where name = 'tu_O_item')
    drop trigger tu_O_item;

create trigger tu_O_item on O_item for update as
begin
    set nocount on
    update O_item set this.version = this.version + 1
        from O_item this, inserted
        where this.i_id = inserted.i_id
end;

if exists (select 1 from sysobjects where name = 'tu_O_orders')
    drop trigger tu_O_orders;

create trigger tu_O_orders on O_orders for update as
begin
    set nocount on
    update O_orders set this.version = this.version + 1
        from O_orders this, inserted
        where this.o_id = inserted.o_id
end;

if exists (select 1 from sysobjects where name = 'tu_O_orderline')
    drop trigger tu_O_orderline;

create trigger tu_O_orderline on O_orderline for update as
begin
    set nocount on
    update O_orderline set this.version = this.version + 1
        from O_orderline this, inserted
        where this.ol_o_id = inserted.ol_o_id and this.ol_id = inserted.ol_id
end;

if exists (select 1 from sysobjects where name = 'tu_S_component')
    drop trigger tu_S_component;

create trigger tu_S_component on S_component for update as
begin
    set nocount on
    update S_component set this.version = this.version + 1
        from S_component this, inserted
        where this.comp_id = inserted.comp_id
end;

if exists (select 1 from sysobjects where name = 'tu_S_purchase_order')
    drop trigger tu_S_purchase_order;

create trigger tu_S_purchase_order on S_purchase_order for update as
begin
    set nocount on
    update S_purchase_order set this.version = this.version + 1
        from S_purchase_order this, inserted
        where this.po_number = inserted.po_number
end;

if exists (select 1 from sysobjects where name = 'tu_S_purchase_orderline')
    drop trigger tu_S_purchase_orderline;

create trigger tu_S_purchase_orderline on S_purchase_orderline for update as
begin
    set nocount on
    update S_purchase_orderline set this.version = this.version + 1
        from S_purchase_orderline this, inserted
        where this.pol_number = inserted.pol_number and this.pol_po_id = inserted.pol_po_id
end;

if exists (select 1 from sysobjects where name = 'tu_S_site')
    drop trigger tu_S_site;

create trigger tu_S_site on S_site for update as
begin
    set nocount on
    update S_site set this.version = this.version + 1
        from S_site this, inserted
        where this.site_id = inserted.site_id
end;

if exists (select 1 from sysobjects where name = 'tu_S_supplier')
    drop trigger tu_S_supplier;

create trigger tu_S_supplier on S_supplier for update as
begin
    set nocount on
    update S_supplier set this.version = this.version + 1
        from S_supplier this, inserted
        where this.supp_id = inserted.supp_id
end;

if exists (select 1 from sysobjects where name = 'tu_S_supp_component')
    drop trigger tu_S_supp_component;

create trigger tu_S_supp_component on S_supp_component for update as
begin
    set nocount on
    update S_supp_component set this.version = this.version + 1
        from S_supp_component this, inserted
        where this.sc_p_id = inserted.sc_p_id and this.sc_supp_id = inserted.sc_supp_id
end;

