update EAI_EFFECT_SALE set UUID = UUID_CREATE();
update INVENT set UUID = UUID_CREATE();
update MENU_GROUP set UUID = UUID_CREATE();
update MENU_HEAD set UUID = UUID_CREATE();
update MENU_PRICE_LIST set UUID = UUID_CREATE();
update NOM_DISCOUNT set UUID = UUID_CREATE();
update NOM_OBJECT set UUID = UUID_CREATE();
update STOCK set UUID = UUID_CREATE();
update STOCK_GROUP set UUID = UUID_CREATE();
update SYSTEM_END_WORK set UUID = UUID_CREATE();


update NOM_DISCOUNT d
set    d.DISCOUNT_NAME = d.DISCOUNT_NAME || '*' || d.ID_DISCOUNT
where  exists (select t.ID_DISCOUNT
               from   NOM_DISCOUNT t
               where  t.DISCOUNT_NAME = d.DISCOUNT_NAME
                      and t.ID_DISCOUNT < d.ID_DISCOUNT)
order by d.ID_DISCOUNT asc;

commit work;

update INVENT i
set    i.INVENT_NAME = i.INVENT_NAME || '*' || i.ID_INVENT
where  exists (select t.ID_INVENT
               from   INVENT t
               where  t.INVENT_NAME = i.INVENT_NAME
                      and t.ID_INVENT < i.ID_INVENT)
order by i.ID_INVENT asc;

commit work;

update MENU_PRICE_LIST pl
set    pl.PRICE_LIST_NAME = pl.PRICE_LIST_NAME || '*' || pl.ID_MENU_PRICE_LIST,
       pl.UUID = UUID_CREATE()
where  exists (select t.ID_MENU_PRICE_LIST
               from   MENU_PRICE_LIST t
               where  t.PRICE_LIST_NAME = pl.PRICE_LIST_NAME
                      and t.ID_MENU_HEAD is not distinct from pl.ID_MENU_HEAD
                      and t.ID_MENU_PRICE_LIST < pl.ID_MENU_PRICE_LIST)
order by pl.ID_MENU_PRICE_LIST asc;

commit work;

update CONTRAGENT c
set    c.CONTRAGENT_NAME = c.CONTRAGENT_NAME || '*' || c.ID_CONTRAGENT,
       c.UUID = iif(c.ID_CONTRAGENT = 0, cast('contragent-bez-contragent' as varchar(30)), MD5HASH(c.CONTRAGENT_NAME))
where  exists (select t.ID_CONTRAGENT
               from   CONTRAGENT t
               where  t.CONTRAGENT_NAME = c.CONTRAGENT_NAME
                      and t.ID_CONTRAGENT < c.ID_CONTRAGENT)
order by c.ID_CONTRAGENT asc;

commit work;

update NOM_PAYMENT_TYPE pt
set    pt.PAYMENT_NAME = pt.PAYMENT_NAME || '*' || pt.ID_PAYMENT_TYPE,
       pt.UUID = iif(pt.ID_PAYMENT_TYPE = 0, cast('tova_e_nulevoto_plashtane' as varchar(30)), MD5HASH(pt.PAYMENT_NAME))
where  exists (select t.ID_PAYMENT_TYPE
               from   NOM_PAYMENT_TYPE t
               where  t.PAYMENT_NAME = pt.PAYMENT_NAME
                      and t.ID_PAYMENT_TYPE < pt.ID_PAYMENT_TYPE)
order by pt.ID_PAYMENT_TYPE asc;

commit work;

update NOM_VAT_GROUP vg
set    vg.VAT_NAME = vg.VAT_NAME || '*' || vg.ID_VAT,
       vg.UUID = MD5HASH(vg.VAT_NAME)
where  exists (select t.ID_VAT
               from   NOM_VAT_GROUP t
               where  t.VAT_NAME = vg.VAT_NAME
                      and t.ID_VAT > vg.ID_VAT)
order by vg.ID_VAT desc;

commit work;

update NOM_VAT_GROUP vg set UUID = MD5HASH(vg.VAT_NAME);
update NOM_PAYMENT_TYPE pt set UUID = iif(pt.ID_PAYMENT_TYPE = 0, cast('tova_e_nulevoto_plashtane' as varchar(30)), MD5HASH(pt.PAYMENT_NAME));
update CONTRAGENT c set UUID = iif(c.ID_CONTRAGENT = 0, cast('contragent-bez-contragent' as varchar(30)), MD5HASH(c.CONTRAGENT_NAME));
update MENU_PRICE_LIST set UUID = UUID_CREATE();

commit work;

delete
from   SETTING_NAME sn
where  not exists (select s.ID_SETTING
                   from   setting s
                   where  s.ID_SETTING = sn.ID_SETTING);

commit work;


