exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 180 discussion

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

You have a table that was created by running the following Transact-SQL statement:

You need to query the Courses table and return the result set as JSON. The output from the query must resemble the following format:

  • A. SELECT CourseID AS [Course ID], Course as Name FROM Courses FOR JSON PATH('Courses')
  • B. SELECT CourseID AS 'Course ID', Course AS Name FROM Courses FOR JSON ROOT('Courses')
  • C. SELECT CourseID AS [Course ID], Course AS Name FROM Courses FOR JSON AUTO, ROOT('Courses')
  • D. SELECT CourseID AS 'Course ID', Course AS Name FROM Courses FOR JSON AUTO, INCLUDE_NULL_VALUES('Courses')
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️
References:
https://docs.microsoft.com/en-us/sql/relational-databases/json/include-null-values-in-json-include-null-values-option?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
Dieter
Highly Voted 5 years, 10 months ago
In my test this is not possible. Correct answer should be C.Since Auto formats the JSON Output automatically due to this requirements, in addtion the ROOT Parameter defines the root node in the output.
upvoted 19 times
AshleyLiang
5 years, 10 months ago
But Nulls are by default excluded from the JSON output, for both AUTO and PATH modes.
upvoted 1 times
...
...
prakash101179
Highly Voted 5 years, 8 months ago
C is right answer. D would have been right if it would have 'SELECT CourseID AS 'Course ID', Course AS Name FROM Courses FOR JSON AUTO, INCLUDE_NULL_VALUES, ROOT('Courses')' instead of 'SELECT CourseID AS 'Course ID', Course AS Name FROM Courses FOR JSON AUTO, INCLUDE_NULL_VALUES('Courses') '
upvoted 8 times
...
Billybob0604
Most Recent 4 years, 5 months ago
The null values are not a specfic requirement , otherwise this would be the answer SELECT CourseID AS 'Course ID', Course AS Name FROM #Courses FOR JSON AUTO, ROOT('Courses'),INCLUDE_NULL_VALUES
upvoted 1 times
...
Joce_IT
4 years, 11 months ago
We cannot have INCLUDE_NULL_VALUES('Courses'). It is only INCLUDE_NULL_VALUES. https://docs.microsoft.com/en-us/sql/relational-databases/json/include-null-values-in-json-include-null-values-option?view=sql-server-ver15.
upvoted 3 times
...
Anette
5 years ago
Tested. Its C
upvoted 3 times
...
Carol181188
5 years, 1 month ago
https://docs.microsoft.com/en-us/sql/relational-databases/json/format-query-results-as-json-with-for-json-sql-server?view=sql-server-ver15
upvoted 2 times
...
daniel_yes23
5 years, 1 month ago
C is the right answer, this was tested and it works fine CREATE TABLE #Courses ( CourseID INT IDENTITY(1, 1) NOT NULL, Course VARCHAR(50) NULL ) go insert into #Courses (Course) values ('Database Development'), ('Programing in C#') select * from #Courses SELECT CourseID AS 'Course ID', Course AS Name FROM #Courses FOR JSON AUTO, ROOT('Courses')
upvoted 2 times
eduardogtc
4 years, 9 months ago
You're right. In fact all the others give a sintax error. I use your script to test them: select courseid as [Course id], course as name from #courses for json path('Courses' ) select courseid as [Course id], course as name from #courses for json root('Courses' ) select courseid as [Course id], course as name from #courses for json auto, root('Courses' ) select courseid as [Course id], course as name from #courses for json auto, include_null_values('Courses' )
upvoted 1 times
...
...
okh
5 years, 9 months ago
Correct answer is C
upvoted 7 times
...
safiullah
5 years, 10 months ago
I agree with Dieter option C should be the correct answer I have ran it maually on PC and only option with AUTO and ROOT will give us the required format. C. SELECT CourseID AS [Course ID], Course AS Name FROM Courses FOR JSON AUTO, ROOT('Courses')
upvoted 6 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 ...