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.)
Explanation:
http://msdn.microsoft.com/en-us/library/ms191432.aspx
The first index created on a view must be a unique clustered index. After the unique clustered index has been created, you can create nonclustered indexes.
http://msdn.microsoft.com/en-us/library/ms191432.aspx
Agree with Indika. The last one should be unique clustered index.
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.
–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