Microsoft 70-761 Querying Data with Transact-SQL Exam Practice Test

Page: 1 / 14
Total 194 questions
Question 1

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.

A database has two tables as shown in the following database diagram:

You need to list all provinces that have at least two large cities. A large city is defined as having a population of at least one million residents. The query must return the following columns:

* tblProvince.ProvinceId

* tblProvince.ProvinceName

* a derived column named LargeCityCount that presents the total count of large cities for the province

Solution: You run the following Transact-SQL statement:

Does the solution meet the goal?



Answer : B

We should use CROSS APPLY rather than OUTER APPLY.

Note:

The APPLY operator allows you to invoke a table-valued function for each row returned by an outer table expression of a query. The table-valued function acts as the right input and the outer table expression acts as the left input. The right input is evaluated for each row from the left input and the rows produced are combined for the final output. The list of columns produced by the APPLY operator is the set of columns in the left input followed by the list of columns returned by the right input.

There are two forms of APPLY: CROSS APPLY and OUTER APPLY. CROSS APPLY returns only rows from the outer table that produce a result set from the table-valued function. OUTER APPLY returns both rows that produce a result set, and rows that do not, with NULL values in the columns produced by the table-valued function.

References:

https://technet.microsoft.com/en-us/library/ms175156(v=sql.105).aspx


Question 2

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 are building a stored procedure that will be used by hundreds of users concurrently.

You need to store rows that will be processed later by the stored procedure. The object that stores the rows must meet the following requirements:

* Be indexable

* Contain up-to-date statistics

* Be able to scale between 10 and 100,000 rows

The solution must prevent users from accessing one another's data.

Solution: You create a user-defined table in the stored procedure.

Does this meet the goal?



Answer : B


Question 3

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 Customer by running the following Transact-SQL statement:

You create a cursor by running the following Transact-SQL statement:

If the credit limit is zero, you must delete the customer record while fetching data.

You need to add the DELETE statement.

Solution: You add the following Transact-SQL statement:

Does the solution meet the goal?



Answer : B

Use a WHERE CURRENT OF clause, which deletes at the current position of the specified cursor.

References:

https://docs.microsoft.com/en-us/sql/t-sql/statements/delete-transact-sql


Question 4

You are performing a code review of stored procedures. Code at line SP03 fails to run (Line numbers are included for reference only.)

You need to ensure that transactions are rolled back when an error occurs.

Which Transact-SQL segment should you insert at line SP07?



Answer : C

Using TRY...CATCH in a transaction

The following example shows how a TRY...CATCH block works inside a transaction. The statement inside the TRY block generates a constraint violation error.

BEGIN TRANSACTION;

BEGIN TRY

-- Generate a constraint violation error.

DELETE FROM Production.Product

WHERE ProductID = 980;

END TRY

BEGIN CATCH

SELECT

ERROR_NUMBER() AS ErrorNumber

,ERROR_SEVERITY() AS ErrorSeverity

,ERROR_STATE() AS ErrorState

,ERROR_PROCEDURE() AS ErrorProcedure

,ERROR_LINE() AS ErrorLine

,ERROR_MESSAGE() AS ErrorMessage;

IF @@TRANCOUNT > 0

ROLLBACK TRANSACTION;

END CATCH;

IF @@TRANCOUNT > 0

COMMIT TRANSACTION;

GO

References:

https://docs.microsoft.com/en-us/sql/t-sql/language-elements/try-catch-transact-sql


Question 5

You run the following Transact-SQL statement:

You use the table to store data about training courses: when they finished the location, and the number of participants in the courses.

You need to display a result set that shows aggregates for all possible combinations of the number of participants.

Which Transact-SQL statement should you run?

A)

B)

C)

D)



Answer : C

The WITH CUBE clause causes the query to compute all possible totals

References:

https://blogs.msdn.microsoft.com/craigfr/2007/09/27/aggregation-with-cube/


Question 6

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 Customer by running the following Transact-SQL statement:

You create a cursor by running the following Transact-SQL statement:

If the credit limit is zero, you must delete the customer record while fetching data.

You need to add the DELETE statement.

Solution: You add the following Transact-SQL statement:

Does the solution meet the goal?



Question 7

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 Customer by running the following Transact-SQL statement:

You create a cursor by running the following Transact-SQL statement:

If the credit limit is zero, you must delete the customer record while fetching data.

You need to add the DELETE statement.

Solution: You add the following Transact-SQL statement:

Does the solution meet the goal?



Answer : B


Page:    1 / 14   
Total 194 questions