EXCITING FEATURES FORSQL DEVS IN SQL 2012Brij Bhushan Mishra
About Me• Brij Bhushan Mishra• Microsoft ASP.NET/IIS MVP• Former CodeProject MVP• Blogger/Author/Speaker• http://brijbhush...
SQL-2012 Enticing features• Contained database• Always On• Column Store Indexes• Visual Studio integration with Management...
Row Store• Relational Data is stored as row wise which further getsstored in page with page size 8KB in HardDisk asRow Sto...
Columnstore index• Pages stores column data and Columns are heavilycompressedColumn 1 Column 1 Column 4 Column 4Page 2Page...
TSQL Enhancement• Sequence Objects• Data Paging• Error handling• Exec Procs with Result Set• Metadata discovery• Logical f...
Sequence Objects• A user defined object that returns a sequence of numericvalues• Similar is available with Oracle• Unique...
Data Paging• One of the most used features in Applications• Most of the application implements Paging at Applicationlevel ...
Error handling• SQL Server 2005 introduced try/catch (But throw wasmissing)• But to send the error to client, required to ...
EXEC Stored Proc with Result Sets• Can specify a new option with the EXECUTE statementasEXECUTE <proc> WITH <result_set_op...
Metadata Discovery• Earlier we used SET FMTONLY ON that is used to returnthe metadata only (Not the actual data)• Very hel...
Logical and String Functions• IIF• Takes a boolean expression and returns one of the two given values.• Shorthand of Case ...
Conversion Functions• PARSE• Parse a string and try to convert in provided data type.• Uses the .NET CLR• Raise an error i...
DateTime functions• EOMONTH (start_date)• DATEFROMPARTS (year, month, day)• DATETIME2FROMPARTS (year, month, day, hour,min...
Analytic function Lead() and Lag()• LAG() – Access the data in the previous row from thesame result set without self join•...
Thank you• http://brijbhushan.net• @brij_bhushan• brij.mishra@outlook.com
Upcoming SlideShare
Loading in …5
×

Exciting Features for SQL Devs in SQL 2012

742 views
673 views

Published on

Published in: Technology
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total views
742
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
20
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

Exciting Features for SQL Devs in SQL 2012

  1. 1. EXCITING FEATURES FORSQL DEVS IN SQL 2012Brij Bhushan Mishra
  2. 2. About Me• Brij Bhushan Mishra• Microsoft ASP.NET/IIS MVP• Former CodeProject MVP• Blogger/Author/Speaker• http://brijbhushan.net• @brij_bhushan• brij.mishra@outlook.com
  3. 3. SQL-2012 Enticing features• Contained database• Always On• Column Store Indexes• Visual Studio integration with Management Studio• TSQL Enhancements
  4. 4. Row Store• Relational Data is stored as row wise which further getsstored in page with page size 8KB in HardDisk asRow StoreColumn 1 Column 2 Column 3 Column 4 Column 5 Column 1 Column 2 Column 3 Column 4 Column 5Page 1 Page 2Column 1Hits multiple rows to fetch the data
  5. 5. Columnstore index• Pages stores column data and Columns are heavilycompressedColumn 1 Column 1 Column 4 Column 4Page 2Page 1• Removes redundancy and provide faster searchLimitations• 1 Table can have only one 1 Columnstore index• After creating Columnstore index table cannot be updated
  6. 6. TSQL Enhancement• Sequence Objects• Data Paging• Error handling• Exec Procs with Result Set• Metadata discovery• Logical functions and String Functions• Conversion functions• Date Time functions• Analytic Functions LEAD() and LAG()
  7. 7. Sequence Objects• A user defined object that returns a sequence of numericvalues• Similar is available with Oracle• Unique to database, not to a Table (Not like IdentityColumn)• Can be used anywhere not specific to a Table• Does not support TransactionParametersType (Integer) MAXVALUESTART WITH <constant> CYCLE | NO CYCLEINCREMENT BY <constant> CACHE <constant> | NO CACHEMINVALUEDEMO
  8. 8. Data Paging• One of the most used features in Applications• Most of the application implements Paging at Applicationlevel (not a database level)• Currently for Database level Paging• Retrieve data using ROW_NUMBER function• Temp Tables• Other options..• SQL 2012 simplified this• Need to set the offset command• The number of Rows that required to be fetched by using “FETCH”commandDEMO
  9. 9. Error handling• SQL Server 2005 introduced try/catch (But throw wasmissing)• But to send the error to client, required to useRAISEERROR• Throw is added (similar like C# or vb.NET)• Now do not required to add a entry in Sys.Messages table• The original exception is sent to the Client.DEMO
  10. 10. EXEC Stored Proc with Result Sets• Can specify a new option with the EXECUTE statementasEXECUTE <proc> WITH <result_set_option>• Allows to change the column names and data types inResult SetsDEMO
  11. 11. Metadata Discovery• Earlier we used SET FMTONLY ON that is used to returnthe metadata only (Not the actual data)• Very helpful, in scenarios where we cannot predict theresult set.• Two new Proc and equivalent DMV introduced• sp_describe_first_result_set• sp_describe_undeclared_parameters• sys.dm_exec_describe_first_result_set• sys.dm_exec_describe_first_result_set_for_objectDEMO
  12. 12. Logical and String Functions• IIF• Takes a boolean expression and returns one of the two given values.• Shorthand of Case expression• Can be nested upto 10 levels• CHOOSE• Returns a value from the list based on the provided Index• If does not find then returns null• DataType is returned based on the precedence• FORMAT• FORMAT function for locale-aware formatting of date/time andnumber values as strings• CONCAT• Concatenates two or more strings
  13. 13. Conversion Functions• PARSE• Parse a string and try to convert in provided data type.• Uses the .NET CLR• Raise an error if not able to convert it• TRY_PARSE• Similar to parse but returns null if unable to parse• Also uses the .NET CLR• TRY_CONVERT• Similar to Convert but returns null if unable to parseDEMO
  14. 14. DateTime functions• EOMONTH (start_date)• DATEFROMPARTS (year, month, day)• DATETIME2FROMPARTS (year, month, day, hour,minute, seconds, fractions, precision)• DATETIMEFROMPARTS (year, month, day, hour, minute,seconds, milliseconds)• DATETIMEOFFSETFROMPARTS (year, month, day,hour, minute, seconds, fractions, hour_offset,minute_offset, precision)• SMALLDATETIMEFROMPARTS (year, month, day, hour,minute)• TIMEFROMPARTS (hour, minute, seconds, fractions,precision)
  15. 15. Analytic function Lead() and Lag()• LAG() – Access the data in the previous row from thesame result set without self join• Parameters• scalar_expression• Offset• Default• Over([partition_by_clause] order_by_clause) *• Lead() - Access the data in the subsequent row from thesame result se• scalar_expression• Offset• Default• Over([partition_by_clause] order_by_clause) *.
  16. 16. Thank you• http://brijbhushan.net• @brij_bhushan• brij.mishra@outlook.com

×