Click here to Skip to main content
15,908,581 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hi
i have purchase, sales table . also i have a currentstock table. iwant to add and update items to currentstock table using triggers.

Thanks in advance
Posted

Man, you can use stored procedure instead of trigger for this operation.

Inside the stored procedure, write Insert query for the Transaction Table & then for Stock table.

example looks like

SQL
CREATE PROCEDURE UspSALES
(...arguments...)
BEGIN

INSERT INTO SALES_TABLE(...fields...) VALUES(...values...)

--STOCK SHOULD BE DECREASED
UPDATE STOCK_TABLE SET (...fields...)=(...values...)

END

CREATE PROCEDURE UspPURCHASE
(...arguments...)
BEGIN

INSERT INTO PURCHASE_TABLE(...fields...) VALUES(...values...)

--STOCK SHOULD BE INCREASED
UPDATE STOCK_TABLE SET (...fields...)=(...values...)

END

please let me know if you have any doubt
 
Share this answer
 
Why do you want to use triggers ? Are you sure they are the best solution ? What have you tried ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900