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')
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.
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') '
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
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.
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')
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' )
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
...
This section is not available anymore. Please use the main Exam Page.70-761 Exam Questions
Log in to ExamTopics
Sign in:
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.
Dieter
Highly Voted 5 years, 10 months agoAshleyLiang
5 years, 10 months agoprakash101179
Highly Voted 5 years, 8 months agoBillybob0604
Most Recent 4 years, 5 months agoJoce_IT
4 years, 11 months agoAnette
5 years agoCarol181188
5 years, 1 month agodaniel_yes23
5 years, 1 month agoeduardogtc
4 years, 9 months agookh
5 years, 9 months agosafiullah
5 years, 10 months ago