Question 6 of 254
SIMULATION -
You have a database that contains the tables shown in the exhibit. (Click the Exhibit button.)
Exam 70-461: Question 6 - Image 1
You need to create a query that calculates the total sales of each OrderId from the Sales.Details table. The solution must meet the following requirements:
✑ Use one-part names to reference columns.
✑ Sort the order of the results from OrderId.
✑ NOT depend on the default schema of a user.
✑ Use an alias of TotalSales for the calculated ExtendedAmount.
✑ Display only the OrderId column and the calculated TotalSales column.
Which code segment should you use?
To answer, type the correct code in the answer area.
    Correct Answer:

Question 7 of 254
You have a Microsoft SQL Server database that contains tables named Customers and Orders.
The tables are related by a column named CustomerID.
You need to create a query that meets the following requirements:
✑ Returns the CustomerName for all customers and the OrderDate for any orders that they have placed.
✑ Results must include customers who have not placed any orders.
Which Transact-SQL query should you use?
    Correct Answer: D

    To achieve the requirements of returning the CustomerName for all customers and the OrderDate for any orders that they have placed, and ensuring that the results include customers who have not placed any orders, you need to use a LEFT OUTER JOIN. This join will return all records from the Customers table and the matched records from the Orders table. If there's no match, the result is still a row in the result with NULL in place of the Orders table columns. Therefore, the correct query is: SELECT CustomerName, OrderDate FROM Customers LEFT OUTER JOIN Orders ON Customers.CustomerID = Orders.CustomerID.

Question 8 of 254
You create a stored procedure that will update multiple tables within a transaction.
You need to ensure that if the stored procedure raises a run-time error, the entire transaction is terminated and rolled back.
Which Transact-SQL statement should you include at the beginning of the stored procedure?
    Correct Answer: A

Question 9 of 254
Your database contains two tables named DomesticSalesOrders and InternationalSalesOrders. Both tables contain more than 100 million rows. Each table has a
Primary Key column named SalesOrderId. The data in the two tables is distinct from one another.
Business users want a report that includes aggregate information about the total number of global sales and total sales amounts.
You need to ensure that your query executes in the minimum possible time.
Which query should you use?
    Correct Answer: A

    To achieve the minimum possible execution time for aggregating data from two tables with more than 100 million rows each, it is optimal to use the UNION ALL clause. UNION ALL combines the result sets of both SELECT queries including duplicates and is faster as it doesn't require sorting and removing duplicates like UNION. By wrapping the combined results in a subquery and then performing the COUNT and SUM operations, it efficiently returns the required aggregate information. Option A uses UNION ALL correctly, making it the best choice.

Question 10 of 254
You are a database developer at an independent software vendor. You create stored procedures that contain proprietary code.
You need to protect the code from being viewed by your customers.
Which stored procedure option should you use?
    Correct Answer: B