exam questions

Exam 70-762 All Questions

View all questions & answers for the 70-762 exam

Exam 70-762 topic 1 question 126 discussion

Actual exam question from Microsoft's 70-762
Question #: 126
Topic #: 1
[All 70-762 Questions]

You run the following Transact-SQL statement:

There are multiple unique OrderID values. Most of the UnitPrice values for the same OrderID are different.
You need to create a single index seek query that does not use the following operators:
✑ Nested loop
✑ Sort
✑ Key lookup
Which Transact-SQL statement should you run?

  • A. CREATE INDEX IX_OrderLines_1 ON OrderLines (OrderID, UnitPrice) INCLUDE (Description, Quantity)
  • B. CREATE INDEX IX_OrderLines_1 ON OrderLines (OrderID, UnitPrice) INCLUDE (Quantity)
  • C. CREATE INDEX IX_OrderLines_1 ON OrderLines (OrderID, UnitPrice, Quantity)
  • D. CREATE INDEX IX_OrderLines_1 ON OrderLines (UnitPrice, OrderID) INCLUDE (Description, Quantity)
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️
An index with nonkey columns can significantly improve query performance when all columns in the query are included in the index either as key or nonkey columns. Performance gains are achieved because the query optimizer can locate all the column values within the index; table or clustered index data is not accessed resulting in fewer disk I/O operations.
Note: All data types except text, ntext, and image can be used as nonkey columns.
Incorrect Answers:
C: Redesign nonclustered indexes with a large index key size so that only columns used for searching and lookups are key columns.
D: The most unique column should be the first in the index.
References:
https://docs.microsoft.com/en-us/sql/t-sql/statements/create-index-transact-sql?view=sql-server-2017

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Kuratko
Highly Voted 5 years, 4 months ago
The question is too wide to answer it. It depends how you query the data from the "new NCI", the list should be ordered in the same way how you require in output to prevent "sort", It should containt all all requested columns for output in "list&included" (except the primary key, because it already included in NCI) -> to prevent lookups. Also if you would like to SEEK in the index the predicate should coresponded with the list of NCI. So the question is missing the "query" statement for answer it.
upvoted 5 times
...
geekeek1
Most Recent 4 years, 5 months ago
Answer should be A. Because it follows the correct order for the key columns plus it has both description and qty as included columns. Whereas D has the ordering of the key columns wrong!
upvoted 1 times
...
Alex5x
4 years, 8 months ago
The question is not complete. Without seeing the query we cannot say anything. For example, if the query is: SELECT Description, Quantity, UnitPrice FROM OrderLines WHERE OrderId = @OrderId and UnitPrice > 5, then we should chose A. Howevere, if the query is SELECT Quantity, UnitPrice FROM OrderLines WHERE OrderId = @OrderId and UnitPrice > 5, then we should chose B. If the query is SELECT Quantity, UnitPrice FROM OrderLines WHERE OrderId = @OrderId and UnitPrice > 5 AND Quantity > 10, then we should chose C. D is wrong in any case.
upvoted 2 times
...
Anette
4 years, 12 months ago
I am between A and D and would go for A, because I think there are nested loops from D. Do you agree?
upvoted 3 times
Anette
4 years, 11 months ago
Having clustered index here by default we have Sort. First we have to delete clustered index and then create non clustered index, which probably is A.
upvoted 1 times
...
...
Hoglet
5 years ago
A and B are equally valid without knowing if we require Description C - the Key size is getting unnecessarily large. D - While UnitPrice is unique (within the Order), when we have 1000 Orders, we are not going to have 1000 unique UnitPrice values. And I don't imagine cases where we would want to query or join on the UnitPrice (return only), rather we would to query on OrderId. The only reason to include UnitPrice in the key is if you wanted to return values in UnitPrice order and you have the requirement to not use the SORT operator. Real World Solution - CREATE INDEX IX_OrderLines_1 ON OrderLines (OrderID) INCLUDE (UnitPrice, Description, Quantity) Take the hit of auto-added "uniqueifier", it's 4 bytes, compared to 9 bytes require by UnitPrice. Did you notice that none of the suggested solutions were CREATE UNIQUE INDEX?
upvoted 1 times
...
HPLovesCrafts
5 years ago
Since it says "Most of the UnitPrice values for the same OrderID are different", one has to assume that some values for OrderID does have duplicate UnitPrice values, no? In that case, by the process of elimination, only C seems to work out. Or is there a mistake somewhere?
upvoted 1 times
Anette
4 years, 12 months ago
It most not use Sort. This is much way bad from the other options in this point of viee.
upvoted 1 times
...
...
JohnFan
5 years, 3 months ago
DROP INDEX PreferredName ON Application.People; GO CREATE NONCLUSTERED INDEX PreferredName_Include_FullName ON Application.People ( PreferredName ) INCLUDE (FullName) ON USERDATA;
upvoted 1 times
NhiN
4 years, 5 months ago
This guy gave comments on every question with no conclusion
upvoted 1 times
...
Braindripper
4 years, 5 months ago
another useless comment from JohnFan - thanks
upvoted 6 times
geekeek1
4 years, 5 months ago
Stop trolling Johnfan
upvoted 2 times
...
...
...
gtc108
5 years, 3 months ago
"All data types except text, ntext, and image can be used as nonkey columns." Therefore, it cannot be A or D.
upvoted 1 times
JohnFan
5 years, 3 months ago
In terms of data type, character (or string) is not the same thing with text.
upvoted 10 times
...
...
New_user
5 years, 5 months ago
There are more UnitPrice unique values than unique OrderId. D is correct
upvoted 1 times
Bartek
5 years, 4 months ago
We do not know that. " "Most of the UnitPrice values FOR THE SAME OrderID are different"" Other Orders may ordered this same product with this same UnitPrice
upvoted 11 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...