Home » Microsoft » 70-762 » Which five Transact-SQL segments should you use to develop the solution?
DRAG DROP
You manage a database that includes the tables shown in the exhibit. (Click the Exhibit button.)
You plan to create a DML trigger that reads the value of the LineTotal column for each row in the PurchaseOrderDetail table. The trigger must add the value obtained to the value in the SubTotal column of the PurchaseOrderHeader table.
You need to organize the list to form the appropriate Transact-SQL statement.
Which five Transact-SQL segments should you use to develop the solution? To answer, move the appropriate Transact-SQL segments from the list of Transact-SQL segments to the answer area and arrange them in the correct order.
Table diagram
Select and Place:
Correct Answer:
Explanation/Reference:
Explanation:
Box 1: Create TRIGGER NewPODetail
Box 2: ON PurchaseDetail
Box 3: AFTER INSERT AS Basic syntax:
CREATE TRIGGER trigger_name
ON { table | view }
{ FOR | AFTER | INSTEAD OF }
{ [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }
AS { sql_statement [ ; ] [ ,…n ] | EXTERNAL NAME <method specifier [ ; ] > }
Box 4: Update PurchaseOrderHeader
SET SubTotal = SubTotal + LineTotal
FROM inserted
Box 5: WHERE PurchaserOrderHeader.PurchaseOrderID=
Inserted.PurchaseOrderID
The trigger must read the value of the LineTotal column for each row in the PurchaseOrderDetail table. The trigger must add the value obtained to the value in the SubTotal column of the PurchaseOrderHeader table.
References: https://docs.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql?view=sql-server-2017