こんにちは、ねこです。

自称プログラマのおばちゃんのブログです。いろいろあるよねぇ~。

MCSA SQL Server 2016 /70-762/TableのWithNocheck/CascadeとExtended Event

2019-12-09 13:52:27 | 空手

本日まで、『CBT Nuggets』を『9. Implementing Indexes』のラボまでを網羅。ねむぅーい。

そして、今から『Examtopics』を始めます。

どんな問題があるのかわからないので、どんどん解いていって間違えたものをこちらにメモっときます。

1.

You must modify the ProductReview Table to meet the following requirements:
The table must reference the ProductID column in the Product table

次の要件を満たすために、ProductReviewテーブルを変更する必要があります。
テーブルは、ProductテーブルのProductID列を参照する必要があります。


✑ Existing records in the ProductReview table must not be validated with the Product table.ProductReviewテーブルの既存のレコードは、Productテーブルで検証しないでください。
✑ Deleting records in the Product table must not be allowed if records are referenced by the ProductReview table.ProductReviewテーブルによってレコードが参照されている場合、Productテーブルのレコードを削除できないようにする必要があります。
✑ Changes to records in the Product table must propagate to the ProductReview table.Productテーブルのレコードへの変更は、ProductReviewテーブルに反映される必要があります。

(Google翻訳使い始めました。めっちゃ楽やん。

(うぅ~ん、この辺もう読まんでもいいよ。)You also have the following database tables: Order, ProductTypes, and SalesHistory, The transact-SQL statements for these tables are not available.
You must modify the Orders table to meet the following requirements:
✑ Create new rows in the table without granting INSERT permissions to the table.
✑ Notify the sales person who places an order whether or not the order was completed.
You must add the following constraints to the SalesHistory table:
✑ a constraint on the SaleID column that allows the field to be used as a record identifier
✑ a constant that uses the ProductID column to reference the Product column of the ProductTypes table
✑ a constraint on the CategoryID column that allows one row with a null value in the column
✑ a constraint that limits the SalePrice column to values greater than four
Finance department users must be able to retrieve data from the SalesHistory table for sales persons where the value of the SalesYTD column is above a certain threshold.
You plan to create a memory-optimized table named SalesOrder. The table must meet the following requirements:
✑ The table must hold 10 million unique sales orders.
✑ The table must use checkpoints to minimize I/O operations and must not use transaction logging.
✑ Data loss is acceptable.
Performance for queries against the SalesOrder table that use Where clauses with exact equality operations must be optimized.
You need to enable referential integrity for the ProductReview table.
How should you complete the relevant Transact-SQL statement? To answer? select the appropriate Transact-SQL segments in the answer area.

ProductReviewテーブルの参照整合性を有効にする必要があります。
関連するTransact-SQLステートメントをどのように完成させる必要がありますか? 答える? 回答領域で適切なTransact-SQLセグメントを選択します。


Hot Area:

こりゃ、全部読んでも仕方ない手の問題ですね。なので、青字で書いてある部分のみを読み始めます。「ProductReview」を聞いてます。

<答え>

ALTER TABLE dbo.ProductReview WITH NOCHECK
ADD CONSTRAINT FK_productReview_Product FOREIGN KEY (ProductID)
REFERENCES Product (productID) ON DELETE NO ACTION ON UPDATE CASCADE

WITH NOCHECK

We should use WITH NOCHECK as existing records in the ProductReview table must not be validated with the Product table.

「✑ Existing records in the ProductReview table must not be validated with the Product table.」より、「Product table」によってチェックされたらいけないとありますね。だから答えは「WITH NOCHECK」

ON DELETE NO ACTION ON DELETE NO CASCADE
Deletes should not be allowed, so we use ON DELETE NO ACTION.

「✑ Deleting records in the Product table must not be allowed if records are referenced by the ProductReview table.」もし、値が「ProductReview table」によって参照されている場合、「Product table」からは削除できないとあります。だから「 ON DELETE NO ACTION」が答えの前半。でもどうやったら「参照」されているのかという部分が抜け落ちてるような気がする。それに「UPDATE」じゃなくって「DELETE」になってるよ。。。

Updates should be allowed, so we use ON DELETE NO CASCADE

「✑ Changes to records in the Product table must propagate(伝える) to the ProductReview table.」より「Product table」の変更は「ProductReview table」に反映されるとあり、その点において更新はされることとあります。だから答えは『ON DELETE NO CASCADE』

NO ACTION: the Database Engine raises an error, and the update action on the row in the parent table is rolled back.データベースエンジンがエラーを出し、親テーブルの更新された内容はロールバックされる。

 

CASCADE: corresponding rows are updated in the referencing table when that row is updated in the parent table.親テーブルでの更新は子テーブルに反映される。


Note:

ON DELETE { NO ACTION | CASCADE | SET NULL | SET DEFAULT }
Specifies what action happens to rows in the table that is altered, if those rows have a referential relationship and the referenced row is deleted from the parent table. それらの行に参照関係があり、参照された行が親テーブルから削除された場合、変更されたテーブル内の行に何が起こるかを指定します。
ON UPDATE { NO ACTION | CASCADE | SET NULL | SET DEFAULT }
Specifies what action happens to rows in the table altered when those rows have a referential relationship and the referenced row is updated in the parent table.それらの行に参照関係があり、参照された行が親テーブルで更新されたときに、変更されたテーブル内の行に何が起こるかを指定します。

The default is NO ACTION.

デフォルトはNO ACTIONです。

 

Note:

You must modify the ProductReview Table to meet the following requirements:以下の内容に沿って「ProductReview Table」を完成させること
1. The table must reference the ProductID column in the Product table「Product table」の「ProductID 」コラムを参照させる。
2. Existing records in the ProductReview table must not be validated with the Product table.現在ある「ProductReview table」の値は「Product table」と一緒にチェックされないこと。
3. Deleting records in the Product table must not be allowed if records are referenced by the ProductReview table.「Product table」の削除は「ProductReview table」に参照された値がある以上、行われない。
4. Changes to records in the Product table must propagate to the ProductReview table.「Product table」の変更は「ProductReview table」に反映されるとあり、その点において更新はされること。

https://msdn.microsoft.com/en-us/library/ms190273.aspx

https://msdn.microsoft.com/en-us/library/ms188066.aspx

 


2.

You are experiencing performance issues with the database server.
You need to evaluate schema locking issues, plan cache memory pressure points, and backup I/O problems.
What should you create?

データベースサーバーでパフォーマンスの問題が発生しています。
スキーマロックの問題を評価し、キャッシュメモリのプレッシャーポイントを計画し、I / Oのバックアップの問題を解決する必要があります。
何を作成する必要がありますか?

  • A. a System Monitor report
  • B. a sys.dm_tran_database_transaction dynamic management view query
  • C. an Extended Events session that uses Query Editor
  • D. a Microsoft SQL Profiler trace
<答え>C
Extended Events: considered as "the best way" by the SQL Server purists. You can configure Extended Events to find Locking Issues in SQL Server.一番推奨されているそうな。
 
こちらにとってもよい「Extended Events」の設定をする方法を載せたサイトがあるので、ねこみたく英語読むの嫌な人でもイメージだけでも見てやってください。とってもわかりやすいです。
create new extended event session
 

 

 

あぁ、年のせいかすぐ眠くなる。


最新の画像もっと見る

コメントを投稿