Which four T-SQL statements should you use?

DRAG DROP
You use a Microsoft SQL Server 2012 database. You need to create an indexed view within
the database for a report that displays Customer Name and the total revenue for that customer.
Which four T-SQL statements should you use? (To answer, move the appropriate SQL
statements from the list of statements to the answer area and arrange them in the correct order.)

DRAG DROP
You use a Microsoft SQL Server 2012 database. You need to create an indexed view within
the database for a report that displays Customer Name and the total revenue for that customer.
Which four T-SQL statements should you use? (To answer, move the appropriate SQL
statements from the list of statements to the answer area and arrange them in the correct order.)

Answer:

Explanation:
http://msdn.microsoft.com/en-us/library/ms191432.aspx



Leave a Reply 4

Your email address will not be published. Required fields are marked *


MKL

MKL

Agree with Indika. The last one should be unique clustered index.

Slazenjer_m

Slazenjer_m

You are both wrong. Agreed that the first index should be clustered, but the syntax for a clustered index MUST reference at least TWO column-names in the index definition (CustomerID, CustomerName). When the index would reference only ONE column (in this case, CustomerID), there can only be a unique (non-clustered) index; hence the selected option is the right one.

Slazenjer_m

Slazenjer_m

–Create view with schemabinding
IF OBJECT_ID (‘Sales.vOrders’, ‘view’) IS NOT NULL
DROP VIEW Sales.vOrders;
GO

CREATE VIEW Sales.vOrders
WITH SCHEMABINDING
AS
SELECT SUM(UnitPrice*OrderQty*(1.00-UnitPriceDiscount)) AS Revenue,
OrderDate, ProductID, COUNT_BIG(*) AS COUNT
FROM Sales.SalesOrderDetail AS od, Sales.SalesOrderHeader AS o
WHERE od.SalesOrderID = o.SalesOrderID
GROUP BY OrderDate, ProductID;
GO

–Create an index on the view
CREATE UNIQUE CLUSTERED INDEX IDX_V1
ON Sales.vOrders (OrderDate, ProductID);
GO