exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 8 discussion

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

Note: This question is part of a series of questions that present the same scenario. Each question in the series contains a unique solution that might meet the stated goals. Some question sets might have more than one correct solution, while others might not have a correct solution.
After you answer a question in this section. You will NOT be able to return to it. As a result, these questions will not appear in the review screen.
You have a database that tracks orders and deliveries for customers in North America. The database contains the following tables:

Sales.Customers -


Application.Cities -


Sales.CustomerCategories -

The company's development team is designing a customer directory application. The application must list customers by the area code of their phone number. The area code is defined as the first three characters of the phone number.
The main page of the application will be based on an indexed view that contains the area and phone number for all customers.
You need to return the area code from the PhoneNumber field.
Solution: You run the following Transact-SQL statement:

Does the solution meet the goal?

  • A. Yes
  • B. No
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️
As the result of the function will be used in an indexed view we should use schemabinding.
References:
https://sqlstudies.com/2014/08/06/schemabinding-what-why/

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
CristianCruz
Highly Voted 5 years, 1 month ago
ANSWER B. As the result of the function will be used in an indexed view we should use schemabinding.
upvoted 6 times
...
vlxx
Highly Voted 5 years, 2 months ago
correct answer is A.
upvoted 5 times
...
Anirudh_net
Most Recent 3 years, 3 months ago
answer is B
upvoted 1 times
...
Billybob0604
4 years, 4 months ago
Oredie is right. If you add schemabinding to the function it works : CREATE FUNCTION dbo.AreaCode (@phoneNumber NVARCHAR(20)) RETURNS NVARCHAR(10) with schemabinding AS BEGIN DECLARE @areaCode NVARCHAR(max) Bear in mind that you to refer to schema in the function. Otherwise it still won't work.
upvoted 1 times
...
Vermonster
4 years, 5 months ago
Absolutely B as described because function must be schema-bound to work in a view. If it were schema-bound, it would work
upvoted 1 times
...
vramky
4 years, 5 months ago
ANSWER SHOULD BE A Yes. However, it seems that "WITH SCHEMABINDING" has been omitted as a typo (?) after RETUNRS nvarchar(10). However, if there is no omission, it should be B (No) .
upvoted 1 times
...
vramky
4 years, 5 months ago
correct Answer is A.
upvoted 1 times
...
BabyBee
4 years, 6 months ago
Answer is correct, B. User-defined functions referenced in the view must be created by using the WITH SCHEMABINDING option. Any user-defined functions referenced in the view must be referenced by two-part names, <schema>.<function>... https://docs.microsoft.com/en-us/sql/relational-databases/views/create-indexed-views?view=sql-server-ver15
upvoted 1 times
...
Luzix
4 years, 6 months ago
I don´t understand why do you need a SCHEMABINDING if you are not using any table or view. Do you use directly a parameter.
upvoted 1 times
...
oredie
4 years, 9 months ago
Correct answer is B. An Indexed view must be schemabound, the function used in the view must therefore also be schemabound. Tested: DROP VIEW IF EXISTS dbo.AreaPhoneNumbers; DROP FUNCTION IF EXISTS dbo.areaCode DROP TABLE IF EXISTS sales.PhoneNumbers; GO CREATE TABLE sales.PhoneNumbers ( Id INT identity NOT NULL ,PhoneNumber NVARCHAR(20) NOT NULL ); INSERT INTO sales.PhoneNumbers (PhoneNumber) VALUES ('123-4567-89') ,('234-5678-90'); GO CREATE FUNCTION AreaCode (@phoneNumber NVARCHAR(20)) RETURNS NVARCHAR(10) AS BEGIN DECLARE @areaCode NVARCHAR(max) SELECT TOP 1 @areaCode = value FROM string_split(@phoneNumber, '-') RETURN @areaCode END; GO CREATE VIEW AreaPhoneNumbers WITH schemabinding AS SELECT dbo.AreaCode(PhoneNumbers.PhoneNumber) AreaCode ,PhoneNumbers.PhoneNumber FROM sales.PhoneNumbers; Result: (2 rows affected) Msg 4513, Level 16, State 2, Procedure AreaPhoneNumbers, Line 5 [Batch Start Line 27] Cannot schema bind view 'AreaPhoneNumbers'. 'dbo.AreaCode' is not schema bound.
upvoted 4 times
kiri2020
4 years, 8 months ago
Yes Oredie, you are right! It says in Microsoft documents on the Create Indexed Views page - User-defined functions referenced in the view must be created by using the WITH SCHEMABINDING option. https://docs.microsoft.com/en-us/sql/relational-databases/views/create-indexed-views?view=sql-server-ver15
upvoted 1 times
...
Eazzy
4 years, 7 months ago
The function is schemabound did you not read the code?
upvoted 1 times
...
...
CristianCruz
5 years ago
Answer: B As the result of the function will be used in an indexed view we should use schemabinding.
upvoted 3 times
...
Ilray
5 years, 1 month ago
I don't see VIEW, there is FUNCTION.
upvoted 1 times
...
MML
5 years, 1 month ago
correct is B
upvoted 2 times
...
Anette
5 years, 1 month ago
but i return first 3 characters of phonenumber and that's what the question asks. I think it is OK. So the answer I think is A, don't you think so?
upvoted 3 times
...
tcroots19
5 years, 3 months ago
this returns nvachar(10), but declares it as "max", does that get implicit conversion. And if so, what kind? Realize it should only be 3 long...more just curious at a higher level
upvoted 2 times
...
tcroots19
5 years, 3 months ago
What does schemabinding actually do here? Since there is no table referenced, how does this function actually get involved in the Index? Seems like that would be on the actual query that pulls all Phones
upvoted 1 times
Eazzy
4 years, 7 months ago
to create a indexed view the function has to be schemabound
upvoted 1 times
...
...
indu07
5 years, 4 months ago
no where in the query table name is specified , how will the query know which table it has to use .
upvoted 1 times
flashed
5 years, 4 months ago
try to pay more attention. Don't need any table in this case.
upvoted 1 times
tcroots19
5 years, 3 months ago
right, but if you don't have a table name, what does the SchemaBinding do
upvoted 2 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 ...