Wednesday, January 18, 2012

SqlServer 2012(Denali) New Features

http://www.sqlservergeeks.com/articles/sql-server-bi/80/new-built-in-functions-in-sql-server-2012-denali

 

1:FORCESEEK hint is extended to specify columns used to seek in the specified index

When SQL Server chooses seek over scan while retrieving record details, it will compare key value with search input, based on comparison result, Query engine will move to appropriate page. Suppose, index has multiple columns, if we don't want all key columns to consider, in SQL Server 2012, we can mention the index columns to consider when the index has multiple key columns. .

SELECT CompanyID,CompanyName,Amount
FROM COMPANIES
WITH (FORCESEEK(Idx_Company(CompanyID)))
WHERE CompanyID = 1
 

 2:FORCESCAN Hint added to force query optimizer to choose scan over seek

 

Often while tuning stored procedures, we will see tables have the "seek" operator. Few times one of reason for slow performance is wrong estimates on number of rows. Because of that, there are more chances that query optimizer choose "SEEK" over "SCAN". To force optimizer to choose "SCAN" over "SEEK", FORCESCAN hint has been added.

Select OH.OrderID,OD.ItemName,OH.OrderCost
from OrderHeader OH
INNER JOIN OrderDetails OD WITH (FORCESCAN)
on OH.OrderID = OD.OrderID
 
 3:OVER Clause is enhanced to apply aggregate functions while applying "Order By"
 
Before SQL Server 2012, We can't use "Order By" clause, while we are using aggregate functions in OVER clause. Suppose, to calculate company-wise cumulative revenues per year, we can't take the advantage of aggregate operators with OVER clause.
Below syntax is invalid before SQL Server 2012.

SUM(Amount) OVER (PARTITION BY CompanyID ORDER BY Year)
 
4:PERCENT_RANK()
 
PERCENT_RANK() function will returns the percentage value of rank of the element among its group.
PERCENT_RANK() function value will be
  1. For first element in its group, it will be 0.
  2. For last element in its group, it will be 1.
  3. For remaining elements, it will be ( No. Of Elements Before that Element ) / (Total Elements - 1)

No comments:

Post a Comment