Upload
abhishek-sur
View
184
Download
0
Tags:
Embed Size (px)
DESCRIPTION
SQL Server 2012 enhancements
Citation preview
SQL Server 2012 Database Server Programmability
By Abhishek Sur Microsoft MVP, Client App DevFollow us at Twitter @abhi2434 & @sqlservergeeks
Why SQL Server 2012 ? Always On Contained DatabasesColumn Store IndexesVisual Studio integration with Management StudioTSQL Enhancements
2
ColumnStore Index…
3
The Concept
4
Int Varchar Datetime float
float float float floatInt Int Int Int
RowStore Page
Columnstore Page
• ColumnStore reduces redundancy of data and compression as the data type remains same for the entire page.
• All data for a single column could be retrieved from a non clustered index page.
Limitation• 1 Table can have one
columnstore index.
Introducing SQL Server 2012 Transact-SQL Improvements
5
Introducing SQL Server 2012 Transact-SQL Improvements• Query Pagination• OVER Clause Windowing• Sequences• Metadata Discovery• Enhanced Function Library• General T-SQL-Related Enhancements
Query Pagination
• Common application requirement to retrieve rows− For a given page− For a given page length
−Our Options ??? − Retrieve all and filter in application end− Retrieve data using Row_NUMBER function− Any other options ?
−Denali gives better option for pagination
OVER Clause Windowing• Some existing queries do not optimize well• Example: Details of orders and days since previous order of each product
-- Traditional approach
SELECT rs.ProductKey,rs.OrderDateKey,rs.SalesOrderNumber,rs.OrderDateKey- (SELECT TOP 1 prev.OrderDateKeyFROM dbo.FactResellerSales AS prevWHERE rs.ProductKey=prev.ProductKeyAND prev.OrderDateKey<=rs.OrderDateKeyAND prev.SalesOrderNumber<rs.SalesOrderNumberORDER BY prev.OrderDateKey DESC,prev.SalesOrderNumber DESC)AS DaysSincePrevOrderFROM dbo.FactResellerSales AS rsORDER BY rs.ProductKey,rs.OrderDateKey,rs.SalesOrderNumber;
-- Traditional approach
SELECT rs.ProductKey,rs.OrderDateKey,rs.SalesOrderNumber,rs.OrderDateKey- (SELECT TOP 1 prev.OrderDateKeyFROM dbo.FactResellerSales AS prevWHERE rs.ProductKey=prev.ProductKeyAND prev.OrderDateKey<=rs.OrderDateKeyAND prev.SalesOrderNumber<rs.SalesOrderNumberORDER BY prev.OrderDateKey DESC,prev.SalesOrderNumber DESC)AS DaysSincePrevOrderFROM dbo.FactResellerSales AS rsORDER BY rs.ProductKey,rs.OrderDateKey,rs.SalesOrderNumber;
OVER Clause Windowing• Some existing queries do not optimize well• Example: Details of orders and days since previous order of each product
-- Windowed approach
SELECT ProductKey,OrderDateKey,SalesOrderNumber,OrderDateKey-LAG(OrderDateKey)OVER (PARTITION BY ProductKeyORDER BY OrderDateKey,SalesOrderNumber)AS DaysSincePrevOrderFROM dbo.FactResellerSales AS rsORDER BY ProductKey,OrderDateKey,SalesOrderNumber;
-- Windowed approach
SELECT ProductKey,OrderDateKey,SalesOrderNumber,OrderDateKey-LAG(OrderDateKey)OVER (PARTITION BY ProductKeyORDER BY OrderDateKey,SalesOrderNumber)AS DaysSincePrevOrderFROM dbo.FactResellerSales AS rsORDER BY ProductKey,OrderDateKey,SalesOrderNumber;
OVER Clause Windowing• Some existing queries do not optimize well• Example: Details of orders and days since previous order of each product
Sequences• User-defined object• Not tied to any particular table• Not restricted to being used in a single table• Eases migration from other database engines• Does not support Transaction
Metadata Discovery• Applications need to determine metadata associated with code
batches or stored procedures• New functionality provided as both system stored procedures and
via DMVs−DMVs make the metadata easy to consume in a relational query−Additional DMV option for passing an object ID (helpful for stored procedures or
triggers)
• EXECUTE supports a WITH RESULT SETS clause
System Stored Procedure Equivalent DMV
sp_describe_first_result_set sys.dm_exec_describe_first_result_set
sys.dm_exec_describe_first_result_set_for_object
Enhanced Function Library• New functions added
• LOG function now supports an optional base
Conversion Date and Time Logical and String
Analytic
PARSE DATEFROMPARTS CHOOSE CUME_DIST
TRY_PARSE TIMEFROMPARTS IIF PERCENTILE_DIST
TRY_CONVERT
DATETIMEFROMPARTS CONCAT PERCENTILE_CONT
DATETIME2FROMPARTS FORMAT PERCENT_RANK
SMALLDATETIMEFROMPARTS
FIRST_VALUE
DATETIMEOFFSETFROMPARTS
LAST_VALUE
EOMONTH LEAD
LAG
General T-SQL-Related Enhancements• THROW statement
−Can throw user-errors −Can rethrow any errors in a CATCH block (including system errors)
• Extended Events supports many new events−Mostly relating to memory page allocation
Thank You !
WWW.SQLSERVERGEEKS.COM
WWW.KOLKATAGEEKS.COM