1. Learn
  2. /
  3. Courses
  4. /
  5. Building and Optimizing Triggers in SQL Server

Connected

Exercise

Triggers vs. computed columns

While continuing your analysis of the database, you find two other interesting objects:

  • The table SalesWithPrice has a column that calculates the TotalAmount as Quantity * Price. This is done using a computed column which uses columns from the same table for the calculation.

  • The trigger SalesCalculateTotalAmount was created on the SalesWithoutPrice table. The Price column is not part of the SalesWithoutPrice table, so a computed column cannot be used for the TotalAmount. The trigger overcomes this limitation by using the Price column from the Products table.

Instructions 1/3

undefined XP
    1
    2
    3

Insert new data into SalesWithPrice and then run a SELECT from the same table to verify the outcome.