Вы находитесь на странице: 1из 34

SQL Server 2008

New Developer Features


Michael Coles email: admin@geocodenet.com blog: http://sergeantsql.com

About Me
Microsoft MVP (SQL) Author/coauthor of several books:
Pro T-SQL 2008 Programmers Guide Pro SQL Server 2008 XML Expert SQL Server 2008 Encryption (October 2009) Pro Full-Text Search in SQL Server 2008 Accelerated SQL Server 2008

INTRODUCTION

Dozens of articles online and in print MCITP: Database Developer 2008

Key Improvement Areas


SQL Server 2008 improvements focus on several key areas:
Developer/Programmability DBA/Administration Business Intelligence/Analysis Data Warehousing/ETL Encryption/Security

INTRODUCTION

In this presentation well explore new developer-specific features

Developer Improvements
Productivity
Delighters Row Constructors SSMS Intellisense/Collapsible Code Blocks

INTRODUCTION

Language
Data Types

MERGE statement Composable DML Table-Valued Parameters Grouping Sets

Temporal data types Spatial data types hierarchyid Data Type

XML/XQuery

FLWOR let clause More complete XDM data type support

Delighters
Inline variable assignment

PRODUCTIVITY ENHANCEMENTS

Compound (C-style) assignment operators

Valid compound operators are:

Row Constructors
Specify multiple sets of attributes in clause:

PRODUCTIVITY ENHANCEMENTS

SSMS Intellisense
SQL Server Management Studio (SSMS) Intellisense

PRODUCTIVITY ENHANCEMENTS

SSMS Collapsible Code Blocks


SSMS Collapsible Code Blocks

PRODUCTIVITY ENHANCEMENTS

MERGE Statement
The statement combines conditional , and functionality in a single statement
Specify target, source, match criteria and matched/not matched action You can combine match criteria and actions to form complex merges

LANGUAGE ENHANCEMENTS

Useful for T-SQL set-based ETL solutions

MERGE Statement Syntax


ANSI/ISO SQL standard-defined syntax:

LANGUAGE ENHANCEMENTS

MERGE Statement OUTPUT Clause


The clause can be used with just like with other DML statements Use to return the action performed against a row INSERT, UPDATE or DELETE

LANGUAGE ENHANCEMENTS

Composable DML
You can use the clause to feed input to another SQL DML statement General format:

LANGUAGE ENHANCEMENTS

Composable DML Example

LANGUAGE ENHANCEMENTS

Table-Valued Parameters (TVPs)


Addresses need to pass array of elements to stored procedure/function Solutions prior to SQL Server 2008:
Dynamic SQL SQL injection is a security issue Inefficient query execution plan reuse Delimited string, XML; server-side split Requires custom splitting code on server Avoids security, performance issues

LANGUAGE ENHANCEMENTS

Declaring TVPs
Create a user-defined table type:

LANGUAGE ENHANCEMENTS

Declare a variable of the new table type and populate it:

Using TVPs
Create procedure table type parameter:

LANGUAGE ENHANCEMENTS

Call procedure with table type variable:

TVP Tips
Internally table-valued parameters are treated like table variables
Well-defined scope/current batch Not affected by transaction rollback (beyond the atomic statement scope) No histograms or distribution statistics

LANGUAGE ENHANCEMENTS

Table-valued parameter default is empty table Table-valued parameters must be declared

Grouping Sets
New ISO-compliant subclause of allows custom aggregations Similar to and but much more flexible s are used as placeholders in result set

LANGUAGE ENHANCEMENTS

Grouping Sets Example

LANGUAGE ENHANCEMENTS

New Temporal Types


Classic and data types hold date and time components. SQL Server 2008 introduces four new date/time data types:
Date only, no time component. Time only, no date component. Date and time components. Extended precision and date range. Date, time and time offset components. Extended precision and date range.

NEW DATA TYPES

Temporal Types Comparison


Type Min
Jan. 1, 1753 C.E. 00:00:00.000 Jan. 1, 1900 00:00:00 Jan. 1, 0001 C.E. 00:00:00.0000000

NEW DATA TYPES

Max
Dec. 31, 9999 C.E. 12:59:59.997 Jun. 6, 2079 23:59:00

Storage
8 bytes

4 bytes

Dec. 31, 9999 C.E. 23:59:59.9999999

3 bytes 3 5 bytes (variable fractional seconds) 6 8 bytes (variable fractional seconds) 8 10 bytes (variable fractional seconds)

Jan. 1, 0001 C.E. 00:00:00.0000000 Jan. 1, 0001 C.E. 00:00:00.0000000

Dec. 31, 9999 C.E. 23:59:59.9999999 Dec. 31, 9999 C.E. 23:59:59.9999999

New Temporal Data Functions


system date/time

NEW DATA TYPES

system UTC date/time


system date/time with offset information adds an offset to a date/time value adjusts a value to another offset

Spatial Data Types


SQL Server 2008 supports CLR-based and spatial data types
represents objects on a planar 2D (flat-earth) model represents objects on a geodetic spheroidal reference surface

NEW DATA TYPES

Built-in support for Geography Markup Language (GML), Well-Known Text (WKT) and Well-Known Binary (WKB) formats Supports indexing spatial data for efficient spatial calculations

Spatial Models
model model

NEW DATA TYPES

Spatial Data Type Functionality


Open Geospatial Consortium (OGC) standards Spatial data types can store and manipulate points, linestrings, polygons and collections of these objects Data type methods allow manipulation of spatial objects and calculations on objects
Create and manipulate spatial objects Extract spatial data in different representations (WKT, WKB, GML) Calculate intersection of objects, distance, area, boundary, centroid, length

NEW DATA TYPES

SSMS Spatial Data Preview


You can preview spatial data plotted in SSMS in the new Spatial Results tab

NEW DATA TYPES

hierarchyid Data Type


is a new CLR type supporting hierarchical (tree-structure) data Internally is stored as (always 900 bytes or less) Holds materialized path of a tree Methods that provide tree manipulation and query functionality: , , , , , , , , , Efficient querying can utilize depth-first and breadth-first indexes

NEW DATA TYPES

hierarchyid Data Type Example


column specification:

NEW DATA TYPES

Depth and breadth-first index creation:

hierarchyid Depth-First Query


Depth-first subtree query:

NEW DATA TYPES

hierarchyid Breadth-First Query


Breadth-first query direct child query:

NEW DATA TYPES

XML/XQuery
XQuery FLWOR ( ) expressions now support clause Supports XQuery/XDM , data types Does not require time offset in date/time values (default is UTCZ or +00:00) Date/time values not normalized to UTC; stored with time offset information specified XML DML now supports SQL Server variables in statements

XML/XQUERY ENHANCEMENTS

More Features
Sparse Columns/XML Column Sets Filtered Indexes Large SQL CLR User-Defined Types/Aggregates Wide Tables Row compression Page compression

MORE FEATURES

Questions

THE END

References
Microsoft. SQL Server 2008 Books Online. http://msdn.microsoft.com. Coles, M. Pro T-SQL Programmers Guide, Apress.

THE END

Вам также может понравиться