exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 17 discussion

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

DRAG DROP -
You need to create a stored procedure to update a table named Sales.Customers. The structure of the table is shown in the exhibit. (Click the exhibit button.)

The stored procedure must meet the following requirements:
✑ Accept two input parameters.
✑ Update the company name if the customer exists.
✑ Return a custom error message if the customer does not exist.
Which five Transact-SQL segments should you use to develop the solution? To answer, move the appropriate Transact-SQL segments from the list of Transact-
SQL segments to the answer area and arrange them in the correct order.
NOTE: More than one order of answer choices is correct. You will receive credit for any of the correct orders you select.
Select and Place:

Show Suggested Answer Hide Answer
Suggested Answer:

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
The order is wrong. IF without BEGIN/END will only execute the first statement so the highlighted answer is flat out wrong. 1.CREATE PROCEDURE sales.modcompanyname @custId int, @newname nvarchar(40) as 2.IF NOT EXISTS (SELECT custid FROM Sales.Customers WHERE custid = @custID) 3.BEGIN THROW 55555, 'The customer ID does not exist' , 1 END 4.UPDATE sales.customers SET companyname=@newname where custid=@custID
upvoted 1 times
Vermonster
4 years, 4 months ago
Ignore - looks good - the UPDATE SET is one statement
upvoted 1 times
...
...
SimSql
4 years, 4 months ago
CREATE or alter PROCEDURE modcompanyname @custId int, @newname nvarchar(40) as if exists (SELECT custid From cust where custid = @custId) UPDATE cust SET companyname=@newname where custid=@custID IF NOT EXISTS (SELECT custid FROM Cust WHERE custid = @custID) BEGIN THROW 55555, 'The customer ID does not exist Simon' , 1 END
upvoted 1 times
...
julie2020
4 years, 9 months ago
but question requires 5 statements
upvoted 1 times
...
stm22
4 years, 10 months ago
all comments excellent work! but question requires 5 statements.
upvoted 1 times
...
Lindley
5 years, 3 months ago
@Robintang0924 Excellent, thanks!
upvoted 1 times
...
Robintang0924
5 years, 4 months ago
By given statements, below version should be the optimized one since it only needs to read table once when there is no existing custid in the table. 1.CREATE PROCEDURE sales.modcompanyname @custId int, @newname nvarchar(40) as 2.IF NOT EXISTS (SELECT custid FROM Sales.Customers WHERE custid = @custID) 3.BEGIN THROW 55555, 'The customer ID does not exist' , 1 END 4.UPDATE sales.customers SET companyname=@newname where custid=@custID However, if we can come up something by ourselves, then below should be even better performance since we only need to touch table once no matter we got existing custid in table or not (above solution still need to access table twice when custid existed in table): 1.CREATE PROCEDURE sales.modcompanyname @custId int, @newname nvarchar(40) as 2.UPDATE sales.customers SET companyname=@newname where custid=@custID 3. IF @@ROWCOUNT = 0 4.BEGIN THROW 55555, 'The customer ID does not exist' , 1 END
upvoted 4 times
DEBRA
5 years, 3 months ago
but the response is asking for 5 not 4 sql statements which means is 1. create stored procedure.... 2. if exist .... 3. update... 4. if not exist... 5. throw error
upvoted 19 times
Barbedx
5 years, 3 months ago
but also can be 1. create stored procedure.... 2. if not exist 3. throw error... 4. rollback?(useless) 5. update
upvoted 2 times
...
Anette
5 years ago
Yes. And the answer is correct in the answer area.
upvoted 1 times
...
...
Hoglet
4 years, 5 months ago
Definitely the real world answer, but not the "right" answer. Hey ho
upvoted 2 times
...
eggzamtaker
4 years, 5 months ago
update.. if @@rowcount = 0 throw ^ this is the best answer, unfortunately, these choices are not available
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