Dev Sql Beyond Relational

29

description

 

Transcript of Dev Sql Beyond Relational

Page 1: Dev Sql Beyond Relational
Page 2: Dev Sql Beyond Relational

Beyond RelationalPraveen SrivatsaDirector, AsthraSoft ConsultingMicrosoft Regional Director, BangaloreSession Code:

Page 3: Dev Sql Beyond Relational

Why beyond relational?SQL support for non-relational data

A large part of the world’s data is non-relational. ThinkEmails, Pictures, Videos, Chat transcripts, Office docs etc.

SQL Server has support for XML and CLR since SQL 2005 FileStream, Spatial and HierarchyID since SQL 2008

Integrated business scenariosAttachments, free text documents, notes, imagesMedical/Scientific dataGeo spatial, location aware data

Page 4: Dev Sql Beyond Relational

SQL Server 2005 and XML data

Native XML data typeXML Schema support in database

Mapping of SQL Server types to XSD typesXQuery support

Exposed as methods on XML data typeXQuery strings are input to these methods

XML IndexesMany improvements to SELECT...FOR XMLXML input from file system through BULK data provider.NET XML APIs available through SQLCLR SQLXML functionality ships with databaseSSIS supports XML input through adapter

Page 5: Dev Sql Beyond Relational

SQL Server 2008 XML Enhancements

Mapping of new date/time data types to XSD typesSupport for more XML Schema constructs

Union and list typesMany industry-standard XSD schemas use this

Lax validation of xsd:any wildcardsOffice documents and other XSD schemas use this

XQuery support for 'let' clause in FLWOR expressionsXML DML supports insert of XML data type

Page 6: Dev Sql Beyond Relational

Using XML in SQL Serverdemo

Page 7: Dev Sql Beyond Relational

Reliability, Scalability, and Security

SQL Server loads the .NET runtime in-process and guarantees reliability/scalability/security

.NET 2.0 hosting APIs allow host controlAll .NET resources managed and tracked by SQL Server

.NET 2.0 libraries must be safe to run in SQL ServerSystem assemblies divided into 'safe' and 'unsafe'

User code divided into three classificationsSafe - in process calls only, code is reliableExternal - some out of process calls, code is reliableUnsafe - all out of process, reliability not guaranteed

Page 8: Dev Sql Beyond Relational

User-Defined Operations

CLR Supports User Defined Data types, functions, aggregates and table valued functionsScalar UDFs without data access is where .NET excelsSQL Server 2008 include types exposed using SQLCLR

HierarchyIDGeographyGeometry

Page 9: Dev Sql Beyond Relational

TVF and UDA with SQL CLRdemo

Page 10: Dev Sql Beyond Relational

Filestream storage

Storing large binary objects in databases is suboptimal

Large objects take buffers in database memoryLarge objects cause database fragmentation

In file system however, "update" is delete and insert"Before image" in an update is not deleted immediately

Storing all related data in a database addsTransactional consistencyIntegrated, point-in-time backup and restoreSingle storage and query vehicle

Page 11: Dev Sql Beyond Relational

SQL Server 2008 Filestream

A filegroup for filestream storage is declared using DDLFilestream storage is tied to a database

The filegroup is mapped to a directoryMust be NTFS file systemCaution: Files deleteable from file system if you have appropriate permissions

VARBINARY(MAX) columns can be defined with FILESTREAM attribute

Table must also have UNIQUEIDENTIFIER columnFilestream storage not available for other large types

Data is stored in the file system

Page 12: Dev Sql Beyond Relational

Programming with Filestreams

Filestream columns are available with SQL methods

If SQL is used, indistinguishable from varbinary(max)

Filestream can be accessed and modified using file IO

PathName function retrieves a symbolic path nameAcquire context with

GET_FILESTREAM_TRANSACTION_CONTEXTUse OpenSqlFilestream to get a file handle

Page 13: Dev Sql Beyond Relational

FileStream in SQLdemo

Page 14: Dev Sql Beyond Relational

Hierarchical Data

Hierarchical data consists of nodes and edgesHierarchical data can be modeled in relational as

Adjacency model - separate column for edgeMost common, column can either be in same or separate table

Path Enumeration model - column w/hierarchical pathNested Set model - adds "left" and "right" columns to represent edges, which must be maintained separately

Page 15: Dev Sql Beyond Relational

SQL Server and Hierarchical Data

SQL Server 2005 adds Native Hierarchical Queries

Recursive common table expressionANSI-standard

Hierarchical Data can be modeled as XMLXML data type uses ORDPATH format to store elements, attributes and hierarchical constructs

Variable length to 900 bytesComparable type - can be used as index key

Page 16: Dev Sql Beyond Relational

SQL Server and Hierarchical Data

In SQL 2008, new Built-In Data Type - HierarchyIDSQLCLR based system UDT

Useable on .NET clients directly as SqlHierarchyIdAn implementation of path enumeration model

Uses ORDPATH internally for speed

Page 17: Dev Sql Beyond Relational

Working with HierarchyID

Nodes can be added with serializable transactionAfter computing last child

UPDATE Org SET @last_child = LastChild = EmployeeId.GetDescendant(LastChild,NULL)WHERE EmployeeId = @mgridINSERT Org (EmployeeId, EmployeeName) VALUES(@last_child, @EmpName)

Node can be added with error detectionBEGININS_EMP: SELECT @last_child = MAX(EmployeeId) FROM Org_T1 WHERE EmployeeId.GetAncestor(1) = @mgrid INSERT Org_T1 (EmployeeId, EmployeeName) SELECT @mgrid.GetDescendant(@last_child, NULL), @EmpName -- On error, return to INS_EMP to recompute @last_child IF @@error <> 0 GOTO INS_EMP END

Page 18: Dev Sql Beyond Relational

Uisng the HierarchyIDdemo

Page 19: Dev Sql Beyond Relational

Spatial Data

Spatial data provides answers to location-based queries

Which roads intersect the Microsoft campus?Does my land claim overlap yours?List all of the Italian restaurants within 5 kilometers

Spatial data is part of almost every databaseIf your database includes an address

Page 20: Dev Sql Beyond Relational

SQL Server 2008 and Spatial Data

SQL Server supports two spatial data typesGEOMETRY - flat earth modelGEOGRAPHY - round earth model

Both types support all of the instanciable OGC types

InstanceOf method can distinguish between themSupports two dimension data

X and Y or Lat and Long membersZ member - elevation (user-defined semantics)M member - measure (user-defined semantics)

Page 21: Dev Sql Beyond Relational

GEOGRAPHY Requirements

GEOGRAPHY type has additional requirementsCoordinate order is Latitude/Longitude

This will be changed to Longitude/Latitude before RTM

Exterior polygon rings must have their describing coordinates in counter-clockwise order (left-hand rule) with interior rings (holes) in clockwise-order (right-hand rule) A single GEOGRAPHY object cannot span more than a logical hemisphere

Page 22: Dev Sql Beyond Relational

Sample QueryWhich roads intersect Microsoft’s main campus?

SELECT * FROM roads WHERE roads.geom.STIntersects(@ms)=1

Page 23: Dev Sql Beyond Relational

Working with Spatial Datademo

Page 24: Dev Sql Beyond Relational

Beyond relational?Making sense of your data

SQL Server stores relational and non-relational data

XML and CLR support improves with each releaseFilestream storage stores BLOBs on file system

Buffer, fragmentation savingsSpatial data has

Library of spatial functionsThree standard input and output formats

Design all the data for your applications and choose the right model to deploy the data.

Page 25: Dev Sql Beyond Relational

धन्यवा�दઆભા�ર ধন্য�বা�দ

ਧੰ�ਨਵਾ�ਦ

ଧନ୍ୟ�ବା�ଦ

நன்றி�

ధన్య�వాదాలు� ಧನ್ಯ�ವಾ�ದಗಳು

നി�ങ്ങള്‍‌ക്ക്� നിന്ദി�

Page 26: Dev Sql Beyond Relational

question & answer

Page 27: Dev Sql Beyond Relational

Related Content

Breakout Sessions (session codes and titles)

Interactive Theater Sessions (session codes and titles)

Hands-on Labs (session codes and titles)

Hands-on Labs (session codes and titles)

Page 28: Dev Sql Beyond Relational

Track Resources

Resource 1

Resource 2

Resource 3

Resource 4

Page 29: Dev Sql Beyond Relational

© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS,

IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.