【AFTER TRIGGER】
難しい。。。こんな問題があります。
HOTSPOT -
Note: This question is part of a series of questions that use the same scenario. For your convenience, the scenario is repeated in each question. Each question presents a different goal and answer choices, but the text of the scenario is exactly the same in each question in this series.
You have a database named Sales that contains the following database tables: Customer, Order, and Products. The Products table and the Order table are shown in the following diagram.(CustomerとOrderとProductsのテーブルがあります。)
*面倒なので、グーグル使って訳します。
The customer table includes a column that stores the data for the last order that the customer placed.
You plan to create a table named Leads. The Leads table is expected to contain approximately 20,000 records. Storage requirements for the Leads table must be minimized.(顧客テーブルには、顧客が行った最後の注文のデータを格納する列が含まれています。Leadsという名前のテーブルを作成する予定です。 Leadsテーブルには、約20,000件のレコードが含まれると予想されます。 Leadsテーブルのストレージ要件は最小限に抑える必要があります。)
You need to create triggers that meet the following requirements:(次の要件を満たすトリガーを作成する必要があります。)
✑ Optimize the performance and data integrity of the tables.(テーブルのパフォーマンスとデータの整合性を最適化する)
✑ Provide a custom error if a user attempts to create an order for a customer that does not exist.(ユーザーが存在しない顧客の注文を作成しようとした場合、カスタムエラーを提供します。)
✑ In the Customers table, update the value for the last order placed.(顧客テーブルで、最後に出された注文の値を更新します。)
✑ Complete all actions as part of the original transaction.(元のトランザクションの一部としてすべてのアクションを完了します。)
In the table below, identify the trigger types that meet the requirements.(次の表で、要件を満たすトリガータイプを特定しなさい。)
NOTE: Make only selection in each column. Each correct selection is worth one point.(各列でのみ選択を行います。 それぞれの正しい選択には1ポイントの価値があります。)
Hot Area:
さぁ~て、答えは何でしょう。。。
カギはここ。
「Provide custom」->(ユーザーが存在しない顧客の注文を作成しようとした場合、カスタムエラーを提供します。)
「Update Customer table」->(顧客テーブルで、最後に出された注文の値を更新します。)
「AFTER」という言葉に騙されてはいけません!!!大事な部分は「INSERT」と「UPDATE」です。
なぜならトリガーの内容は変更が完結される前に「発動」するから。
詳しくはこちら。T-SQL AFTER TRIGGER トリガーの超簡単説明
<答え>*でもこれまちがってるよねー。『INSTEAD OF INSERT trigger』だと思います。どこにも答えがないから、何とも言えない。
INSTEAD OF INSERT triggers can be defined on a view or table to replace the standard action of the INSERT statement.
AFTER specifies that the DML trigger is fired only when all operations specified in the triggering SQL statement have executed successfully.(INSTEAD OF INSERT(トリガーをビューまたはテーブルで定義して、INSERTステートメントの標準アクションを置き換えることができます。AFTERは、トリガーSQLステートメントで指定されたすべての操作が正常に実行された場合にのみDMLトリガーが起動されることを指定します。)
References:
https://technet.microsoft.com/en-us/library/ms175089(v=sql.105).aspx
※コメント投稿者のブログIDはブログ作成者のみに通知されます