exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 3 discussion

Actual exam question from Microsoft's 70-761
Question #: 3
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 create a table named Products by running the following Transact-SQL statement:

You have the following stored procedure:

You need to modify the stored procedure to meet the following new requirements:
✑ Insert product records as a single unit of work.
✑ Return error number 51000 when a product fails to insert into the database.
If a product record insert operation fails, the product information must not be permanently written to the database.

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: A 🗳️
If the INSERT INTO statement raises an error, the statement will be caught and an error 51000 will be thrown. In this case no records will have been inserted.
Note:
You can implement error handling for the INSERT statement by specifying the statement in a TRY"¦CATCH construct.
If an INSERT statement violates a constraint or rule, or if it has a value incompatible with the data type of the column, the statement fails and an error message is returned.
References:
https://msdn.microsoft.com/en-us/library/ms174335.aspx

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
anonimdom
Highly Voted 5 years, 4 months ago
A single insert statement acts as a transaction. There would be B if there were 2 or more inserts.
upvoted 10 times
tcroots19
5 years, 3 months ago
so, then the answer is A * single unit of work...b/c single INSERT statement (regardless of how many rows passed in) * error message kicks out * bad data not written (even though Rollback isn't done)
upvoted 4 times
...
tz_123
4 years, 11 months ago
Assuming the typos in the code snippet is an accident, then A is correct. This is because the default transaction handling for SQL Server is autocommit.
upvoted 3 times
...
...
chaoxes
Highly Voted 4 years, 10 months ago
It works, so answer should be A. Tested. CREATE TABLE #Products( [ProudctName] [nvarchar](100), [ProductID] [nvarchar](2) ) ON [PRIMARY] GO BEGIN BEGIN TRY INSERT INTO #Products ([ProudctName],[ProductID]) VALUES ('123', '123') END TRY BEGIN CATCH THROW 51000, 'The product could not be created.', 1 END CATCH END
upvoted 6 times
...
Anirudh_net
Most Recent 3 years, 3 months ago
A is Correct
upvoted 1 times
...
Vermonster
4 years, 5 months ago
A is correct. The INSERT statement is a single DML statement. With implicit transaction by default, that would fail and fall through to the CATCH block which handles the error correctly. Don't a transaction and BEGIN/END/COMMIT TRAN with a single DML statement with implicit transaction
upvoted 1 times
...
lh2607
4 years, 5 months ago
If the Insert is not in an explicit transaction, SQL Server automatically performs the operation in an implicit transaction to guarantee atomic behaviour. So for single-statement data modifications, an explicit transaction is not required for all-or-none behaviour. The INSERT will automatically commit or, in the event of an error, rollback. Answer is A
upvoted 2 times
...
kyliek7
4 years, 6 months ago
It works but it's not one unit of work, so it's not correct. - B To make it happen we need begin tran/transaction. FYI, TRAN and TRANSACTION it's the same, for those who thinks it's mispelled. ;)
upvoted 2 times
...
Andy7622
4 years, 7 months ago
Procedure works in general CREATE TABLE Products( ProductId int IDENTITY(1,1) NOT NULL PRIMARY KEY, ProductName nvarchar(100) NULL, UnitPrice decimal (18,2) NOT NULL, UnitsInStock int NOT NULL, UnitsOnOrder int NOT NULL); GO CREATE PROC InsertProducts1 @productname nvarchar(100), @unitprice decimal(18,2), @unitsinstock int, @unitonoder int AS BEGIN BEGIN TRY INSERT INTO Products (ProductName, UnitPrice, UnitsInStock, UnitsOnOrder) VALUES (@productname, @unitprice, @unitsinstock, @unitonoder) END TRY BEGIN CATCH THROW 51000, 'The product could not be created',1 END CATCH END; EXEC InsertProducts1'bike', 160.5, NULL, 2 But it's not created as a single units of works. So, in my opinion correct answer is B.
upvoted 1 times
...
Andy7622
4 years, 7 months ago
The answer must use TRANSACTION . The correct answer is B.
upvoted 1 times
...
TheDUdeu
4 years, 9 months ago
Works 100 % A is the answer.
upvoted 1 times
...
stm22
4 years, 11 months ago
in general, i find that typos on this site are not on the actual exams. the exam might have joins on the wrong columns, but that is intentional to test you.
upvoted 1 times
...
CristianCruz
5 years, 1 month ago
answare is B table columns is productid, productname, unitprice, unitsinstock,unitsonorder and insert of procedure is productname,producprice,productsinstock,productsonorder columns not exists it will not rollback
upvoted 4 times
...
Barbedx
5 years, 3 months ago
So looks like answer is a, but how about incorrect columns names in query(UnitPrices, im mean)? maybe it just mistake, but how about REAL exam question with this case?
upvoted 3 times
...
AnsB
5 years, 4 months ago
the answer is B because it will not rollback
upvoted 2 times
flashed
5 years, 4 months ago
it's not it, it will rollback. It's because MsMartaa and anonimdom said, single insert statement.
upvoted 4 times
tcroots19
5 years, 3 months ago
would this transaction be "doomed"? b/c there is no rollback? so it would actually do the rollback after the transaction times out?
upvoted 1 times
...
...
...
MsMartaa
5 years, 5 months ago
I think that right answer is B, because solution doesn't follow requirement of inserting as a single unit of work (begin/commit transaction)
upvoted 4 times
daniel_yes23
5 years ago
And column table doesn't match with the one in the insert statement
upvoted 1 times
...
kiri2020
4 years, 8 months ago
TRY/CATCH is a single unit of work. Should be A, unless the table columns purposely don't match then it's B.
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 ...