SQL Server and database transactions in Delphi -
i have 2 tables in delphi, sales
, saleitem
, master detail , need calculate totals (sum) of priceitem
column in saleitem
table , save value in pricetotal
column in sales
table.
but need using database transactions. how that? have never done before, , did not find specific allow me on internet.
how use transactions in delphi? i'm using firedac controls , sql server 2014.
you don't need store data in master table, bad design.
calculate in query fetches data master
select salesid, othersalesfields, ( select sum(isnull(saleitem.priceitem, 0)) saleitem saleitem.salesid = sales.salesid ) totalpriceitem sales
now have correct value everytime fetch query , never have worry keeping value in sync, or transaction, or whatever
if must store value in sales (which bad design) not ever in client because cannot keep value in sync. in case make trigger on salesitem table calculate value , update sales table.
Comments
Post a Comment