+ All Categories
Home > Technology > SQL Server2012 Enhancements

SQL Server2012 Enhancements

Date post: 10-May-2015
Category:
Upload: abhishek-sur
View: 178 times
Download: 0 times
Share this document with a friend
Description:
SQL Server 2012 enhancements
Popular Tags:
15
SQL Server 2012 Database Server Programmability By Abhishek Sur Microsoft MVP, Client App Dev Follow us at Twitter @abhi2434 & @sqlservergeeks
Transcript
Page 1: SQL Server2012 Enhancements

SQL Server 2012 Database Server Programmability

By Abhishek Sur Microsoft MVP, Client App DevFollow us at Twitter @abhi2434 & @sqlservergeeks

Page 2: SQL Server2012 Enhancements

Why SQL Server 2012 ? Always On Contained DatabasesColumn Store IndexesVisual Studio integration with Management StudioTSQL Enhancements

2

Page 3: SQL Server2012 Enhancements

ColumnStore Index…

3

Page 4: SQL Server2012 Enhancements

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.

Page 5: SQL Server2012 Enhancements

Introducing SQL Server 2012 Transact-SQL Improvements

5

Page 6: SQL Server2012 Enhancements

Introducing SQL Server 2012 Transact-SQL Improvements• Query Pagination• OVER Clause Windowing• Sequences• Metadata Discovery• Enhanced Function Library• General T-SQL-Related Enhancements

Page 7: SQL Server2012 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

Page 8: SQL Server2012 Enhancements

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;

Page 9: SQL Server2012 Enhancements

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;

Page 10: SQL Server2012 Enhancements

OVER Clause Windowing• Some existing queries do not optimize well• Example: Details of orders and days since previous order of each product

Page 11: SQL Server2012 Enhancements

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

Page 12: SQL Server2012 Enhancements

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

Page 13: SQL Server2012 Enhancements

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

Page 14: SQL Server2012 Enhancements

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

Page 15: SQL Server2012 Enhancements

Thank You !

WWW.SQLSERVERGEEKS.COM

WWW.KOLKATAGEEKS.COM


Recommended