SQL Server 2008 for Developers

23
Building Applications with Building Applications with SQL Server 2008 SQL Server 2008 Lynn Langit http://blogs.msdn.com/SoCal DevGal

description

Slides from my talk on SQL Server 2008 for developers at OC Tech Days November 2008

Transcript of SQL Server 2008 for Developers

Page 1: SQL Server 2008 for Developers

Building Applications with SQL Building Applications with SQL Server 2008Server 2008

Lynn Langit http://blogs.msdn.com/SoCalDevGal

Page 2: SQL Server 2008 for Developers

What Will We cover?

• SQL Server Spatial support• T-SQL Enhancements• Visual Studio integration• SQL CLR• Reporting Services

Page 3: SQL Server 2008 for Developers

What is Spatial Data?

• Spatial data represents locations– Which roads intersect property or each other?– How many stores/restaurants/houses/car dealerships are located within

a geographical area?• Represented by two primary data types

– Geometry: small areas where curvature of the Earth isn’t so relevant• Flat Earth model or X, Y coordinates

– Geography: large areas where the curvature of the Earth does matter• Round Earth model or Latitude and longitude coordinates

• You query for location information as you would any SQL Server data type– Data types dictated by the OpenGIS standard

Page 4: SQL Server 2008 for Developers

Representing Spatial Data

• Stored in proprietary binary format– Can be input using simple text (Parse methods convert text into

internal storage format)

– Represents areas using• Points, Line strings, Polygons• Multi Points, Multi Line strings, Multi Polygons• Geom Collection

• Areas must be defined in counter-clockwise direction, but Interior areas (“holes”) must be defined in clockwise direction

• Spatial Reference ID (SRID) identifies ellipsoid used (flat/round, meters/feet)

– Only instances with like SRID can be directly compared

Page 5: SQL Server 2008 for Developers

Geographical Data

• GEOGRAPHY type has additional requirements– Coordinate order is longitude/latitude– A single GEOGRAPHY object cannot span more than a

logical hemisphere• Will throw exceptions if too large

Page 6: SQL Server 2008 for Developers

DemoDemo

SQL Server Geospatial and SQL Server Geospatial and Virtual EarthVirtual Earth

Page 7: SQL Server 2008 for Developers

Geo Spatial Links

Practical uses for Geospatial data

Series on use of Geospatial data in SQL Server 2008

OpenGIS standards

OGC Methods on Geography Instances

OGC Methods on Geometry Instances

Page 8: SQL Server 2008 for Developers

Enhancements to T-SQL

• Table Value Parameters• New Date/Time types• Time zone awareness• New MERGE keyword• New shorthand notation

Page 9: SQL Server 2008 for Developers

Table Value Parameters

• TVPs are used to insert/update multiple tables at one time– MARS-like capability for writing

• ADO.NET updated to include support– New parameter type:SqlDbType.Structured

– MSDN documentation

Page 10: SQL Server 2008 for Developers

Dates and Time

• Several new types added– datetime2– date– time– datetimeoffset

• New functions added– CONVERT– SYS* Functions– DATEDIFF

Page 11: SQL Server 2008 for Developers

MERGE

• MERGE allows for insert, update, delete with one keyword– Merge two tables, source and target– Target table will be modified based on contents

of source table• Syntax and use can be complex!

– Review BOL for details

Page 12: SQL Server 2008 for Developers

Shorthand Notation

• Allows you to declare a variable and assign a value in one line of code– More like contemporary programming

languages, C# or Visual Basic .NET

Page 13: SQL Server 2008 for Developers

DemoDemo

T-SQL EnhancementsT-SQL Enhancements

Page 14: SQL Server 2008 for Developers

Visual Studio Integration

• Enhanced project types– SQL CLR Database projects– Analysis Services

• OLAP cubes • Data Mining Structures

– Integration Services– Reporting Services

Page 15: SQL Server 2008 for Developers

DemoDemo

Visual Studio IntegrationVisual Studio Integration

Page 16: SQL Server 2008 for Developers

SQL CLR

• SQL Server has the ability to execute managed code– Stored procedures– Functions– Aggregates– Table value functions– User-defined types– Triggers

• Visual Studio can manage both creation and deployment• SQL CLR is “off by default” for security reasons

– Must activate per database to enable• Can be remotely debugged• With great power comes great responsibility

– Your code executes in the SQL Server processing stream

Page 17: SQL Server 2008 for Developers

Programming SQL CLR

• Visual Studio provides templates for the various SQL CLR constructs

– Uses Database project type

– Simply “add new” like any other item you might add

• Metadata controls SQL Server behavior

– Attributes control programmatical type• Microsoft.SqlServer.Server.SqlProcedure• Microsoft.SqlServer.Server.SqlFunction• Microsoft.SqlServer.Server.SqlUserDefinedAggregate• Microsoft.SqlServer.Server.SqlTrigger• Microsoft.SqlServer.Server.SqlUserDefinedType

• You write your logic using a .NET-supported language

• You work with other objects in the Microsoft.SqlServer.Server namespace to retrieve and return data

• Very ADO.NET-like, but not ADO.NET

• Can be assigned security levels

– Safe, External, Unsafe

Page 18: SQL Server 2008 for Developers

DemoDemo

SQL CLRSQL CLR

Page 19: SQL Server 2008 for Developers

Reporting Services

• SQL Server standard for reporting– Managed enterprise reporting / Ad-hoc reporting / Embedded reporting /

Web-based reporting• Reports can be formatted in a variety of ways

– PDF / Word 2007 / HTML, custom• Reports are exposed via a Web Service

– Can be integrated with SharePoint– Dependency on IIS removed (uses http.sys)

• Strong designer and wizard support in Visual Studio– Can also use Report Builder

• Enhanced configuration and administration tool• SSRS available in SQL Server Express 2008 w/Adv Services

Page 20: SQL Server 2008 for Developers

Programming Reports

• Design reports in Visual Studio 2008 SP1– Query for data– Assign query results to report– Design report style

• Colors• Fonts

– Deploy report• Web Service• SharePoint Services• Report Viewer control in Visual Studio

• Wizard available for initial report design

Page 21: SQL Server 2008 for Developers

DemoDemo

Reporting ServicesReporting Services

Page 22: SQL Server 2008 for Developers

For More Information

blogs.msdn.com/SoCalDevGal

www.microsoft.com/sql

Pre-order it now

Page 23: SQL Server 2008 for Developers

Surprise!

Only for attendees of TechDays!