exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 68 discussion

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

You need to create a table named MiscellaneousPayment that meets the following requirements:

Which Transact-SQL statement should you run?

A.

B.

C.

D.

E.

F.

Show Suggested Answer Hide Answer
Suggested Answer: D
Incorrect Answers:
A: For column Reason we must use nvarchar, not varchar, as multilingual values must be supported. NEWSEQUENTIALID cannot be referenced in queries. In addition, the money datatype uses rounding and will result in rounding errors.
B: We cannot use INT for the Id column as new values must be automatically generated.
C: For column Reason we must use nvarchar, not varchar, as multilingual values must be supported.
E: NEWSEQUENTIALID cannot be referenced in queries.
F: The money datatype uses rounding and will result in rounding errors. We should use decimal instead.
Note: Nvarchar stores UNICODE data. If you have requirements to store UNICODE or multilingual data, nvarchar is the choice. Varchar stores ASCII data and should be your data type of choice for normal use.
References:
https://docs.microsoft.com/en-us/sql/t-sql/data-types/nchar-and-nvarchar-transact-sql

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
Vermonster
4 years, 4 months ago
Both D and E fit the criteria. Nothing about performance and the comment about NEWSEQUENTIAL ID in a SQL statement doesn't apply and wasn't even part of the criteria
upvoted 1 times
...
Andy7622
4 years, 4 months ago
Actually, both D and E work
upvoted 1 times
...
Andy7622
4 years, 4 months ago
CREATE TABLE MiscellaneosPayment ( ID uniqueidentifier DEFAULT NEWSEQUENTIALID() PRIMARY KEY , Reason nvarchar(500), Amount decimal(19,4) ) INSERT INTO MiscellaneosPayment(Reason,Amount) VALUES ('Because', 100.4107), ('Due to', 30.2074) SELECT * FROM MiscellaneosPayment; It works
upvoted 1 times
...
Andy7622
4 years, 4 months ago
And what does it mean that NEWSEQUENTIALID cannot be referenced in queries for explanation that E isn't correct. You won't refer this column in INSERT statement it is default
upvoted 1 times
...
Andy7622
4 years, 4 months ago
E is the correct answer
upvoted 1 times
...
Hoglet
4 years, 4 months ago
Firstly, don't use the MONEY type. Secondly, NEWSEQUENTIALID() can be used as a column default. But the requirement is that the ID be "globally unique". This means using the NEWID() function over the NEWSEQUENTIALID() function. NEWID() is slower and will likely cause more index fragmentation if it's on the Primary Key. But to meet the requirement, you need to use NEWID()
upvoted 1 times
...
Alsari
4 years, 4 months ago
newsequentialid is better for insert operations
upvoted 1 times
Hoglet
4 years, 4 months ago
You have to explain why
upvoted 1 times
...
...
Oooo
4 years, 7 months ago
Guys the correct answer is E Let me explain how: one of the requirements for ID column says the value must be (Concentrate on must be) automatcially generated for insert opertaions. You can achieve this by both newid() as well as newsequentialID(), however newid() gives you the liberty of inserting values through an insert statement if you wish to and on the other hand in newsequentialID you cannot do that. The ID must be (again MUST be) generated automatyically no matter what.
upvoted 3 times
SimSql
4 years, 4 months ago
I think both newid() and newsquentialid() allow to insert values through an insert statement if you want to. My guess is we should choose newsquentialid() for it is better to have a squential primary key rather than a random(newid) primary key.
upvoted 1 times
SimSql
4 years, 4 months ago
also NEWSEQUENTIALID is faster to generate and also fills up a complete page due to fill factor.
upvoted 1 times
...
...
...
Deimy
4 years, 8 months ago
The answer should be "B"
upvoted 1 times
Deimy
4 years, 8 months ago
sorry, answer should be D
upvoted 1 times
...
...
melvin9900
4 years, 9 months ago
If you do not need a true random number I suggest you use the NEWSEQUENTIALID as it is faster to generate and also fills up a complete page due to fill factor.
upvoted 1 times
BabyBee
4 years, 5 months ago
The performance will depend on what you're mainly doing. For reads it is faster they are sequential, but for inserts from different sessions it is better they are randomly generated.
upvoted 1 times
...
...
Anette
4 years, 11 months ago
it seems like both D and E are correct :/
upvoted 3 times
Anette
4 years, 11 months ago
Anyway since we have to save data for MiscellaneousPayment for security reason maybe NEWID fits well as it is more secure, as the GUID is randomly generated, and harder to guess.
upvoted 4 times
...
...
daniel_yes23
5 years ago
B generates unique values too
upvoted 4 times
...
AI_Cheong
5 years ago
C, E has the same syntax. newID doesn't generate sequential number tho.
upvoted 2 times
Anette
4 years, 11 months ago
yes but data type for "Reason" differs. And it is used nvarchar for multilingual
upvoted 1 times
...
BabyBee
4 years, 5 months ago
I gave a thumb up when I meant to reply. @Everyone, but where does it specify the ID has to be sequential in the request?
upvoted 1 times
...
...
Hoey
5 years, 1 month ago
Why we cannot use Int as identity datatype? https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql-identity-property?view=sql-server-ver15
upvoted 1 times
xd1
5 years ago
as int identity is only unique to that column
upvoted 3 times
...
...
Joce_IT
5 years, 5 months ago
E could be a correct answer as well. OK, we can read that NEWSEQUENTIALID cannot be referenced in queries. For example at page https://docs.microsoft.com/en-us/sql/t-sql/functions/newsequentialid-transact-sql?view=sql-server-ver15. But it is for a query like: SELECT NEWSEQUENTIALID(); We can also read "NEWSEQUENTIALID() can only be used with DEFAULT constraints on table columns of type uniqueidentifier". It is what I have done in a database. And the query SELECT [Id],[Reason],[Amount] FROM [dbo].[MiscellaneousPayment] works perfectly.
upvoted 3 times
...
M4x
5 years, 7 months ago
E is the correct answer because newsequentialid is more faster that newid. https://docs.microsoft.com/en-US/sql/t-sql/functions/newsequentialid-transact-sql?view=sql-server-2017
upvoted 2 times
Bartek
5 years, 7 months ago
Its no about performance. Its about generating unique key for primary key of table. Newid() is generationg unique surrogate keys and newsequentialid() is generationg nonsequentialid surrogate keys
upvoted 7 times
Bartek
5 years, 7 months ago
So correct is still answer D :)
upvoted 8 times
...
kiri2020
4 years, 6 months ago
it is the opposite, Newid() is generating nonsequential id, and newsequentialid() is generating sequential. For the Primary Key column we want sequential. So the correct answer is E
upvoted 1 times
kimalto452
4 years, 4 months ago
NEWSEQUENTIALID If privacy is a concern, do not use this function. It is possible to guess the value of the next generated GUID and, therefore, access data associated with that GUID.
upvoted 1 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 ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago