Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Lincolnburrows
Yak Posting Veteran
52 Posts |
Posted - 2014-09-20 : 05:47:27
|
I have 2 tables, Portfolio and Transactions. When you insert Transaction_Amount value into the Transactions, the Portfolio should be updated too.I created a Trigger so whenever I insert a value into the Transactions, the Portfolio will be updated too.Below is my MYSQL TriggerUSE `custom_sample`;DELIMITER $$CREATE TRIGGER `Transactions_AINS` AFTER INSERT ON `Transactions` FOR EACH ROWUPDATE Portfolio SET Invest_Amount = Invest_Amount+Transactions.Transaction_AmountwherePortfolio.idPortfolio = Transactions.idPortfolioHowever this didn't work. It says Unknown column Transactions.idPortfolio in where clauseWhat is wrong with my script? |
|
alinazolii
Starting Member
4 Posts |
Posted - 2014-09-20 : 07:40:40
|
The record of the triggered table can be referenced by NEW (or OLD for the values before in case of an update) instead of the table name.quote: CREATE TRIGGER `Transactions_AINS` AFTER INSERT ON `Transactions`FOR EACH ROWUPDATE PortfolioSET Invest_Amount = Invest_Amount + NEW.Transaction_AmountWHERE idPortfolio = NEW.idPortfolio
|
|
|
|
|
|