title: Database trigger to update a row on parent table after child table has been updated
body: <p>First time creating a Database trigger. I have a child table that when its cost column is updated, I need its parent table to also update its cost column to reflect the change.</p>
  
  <p>Here is my sorry attempt so far. That's obviously not working. I am having a problem figuring out how to extract the total cost as a variable and store it in the parent table. </p>
  
  <p>My current approach assumes a static id vaule at the moment. I am not entirely sure how to dynamically determine the id value of the row that was updated.</p>
  
  <pre><code>CREATE TRIGGER ParentCost_Update
  ON ChildTable
  AFTER INSERT, UPDATE 
  
  AS 
  SELECT SUM(Cost) AS TotalCost FROM ChildTable where parent_id=2080
  
  UPDATE ParentTable
      SET Cost=TotalCost
      where id=parent_id;
  
  GO
  </code></pre>
  
  <p>This current script is returning an error</p>
  
  <p><em>Msg 207, Level 16, State 1, Procedure ParentCost_Update, Line 9
  Invalid column name 'TotalCost'.</em></p>