How to update many databases when we update any table?
I am creating a C# Windows application which is based on a medical inventory.In this application I have mainly three forms as PurchaseDetail,SalesDetail,and StockDetail.
Now I want a functionality in which if I insert or modify the records in PurchaseDetail,or SalesDetail, the data in the StockDetail should also be modified.(for example if i insert some quantity of medicines in PurchaseDetail then Quantity in StockDetail should also modified and same as for SalesDetail )
Columns in PurchaseDetail: Id(Primary Key and auto increment int),BatchNumber,MedicineName,ManufacturingDate,ExpiryDate,Rate,MRP,Tax,Discount,Quantity
Columns in SalesDetail: Id(PrimaryKey and auto increment int),BillNumber,CustomerName,BatchNumber,Quantity,Rate,Sale开发者_如何学GosDate
Columns in StockDetail: Id(Primary Key and auto increment int),ProductId,ProductName,OpeningStock,ClosingStock,PurchaseQty,DispenseQty,PurchaseReturn,DispenseReturn
Please help me.
I'm guessing that you are talking about 3 tables in one database (although the title seems to indicate otherwise).
You could use triggers to achieve what you are asking for. (Note that I gave you a tsql example in the link)
OR,
You could write a transactional procedure to perform all steps (or none) at once.
I'm assuming that you mean 'update many tables', not multiple databases.
There are at least 3 ways to do this
- Database Triggers on PurchaseDetail and SalesDetail which also update StockDetail.
- Wrap the inserts into PurchaseDetail or SalesDetail with Stored Procs, which also update the StockDetail accordingly
- Do this from code (in your C# layer), similar to 2.
精彩评论