Praveen Srivatsa
Director, AsthraSoft Consulting
Microsoft Regional Director, Bangalore
Session Code:
Why beyond relational?
SQL support for non-relational data

  A large part of the world’s data is non-relational. Think
  ...
SQL Server 2005 and XML data
 Native XML data type
 XML Schema support in database
    Mapping of SQL Server types to XSD ...
SQL Server 2008 XML
Enhancements
 Mapping of new date/time data types to XSD
 types
 Support for more XML Schema construct...
Using XML in SQL Server
Reliability, Scalability, and Security
 SQL Server loads the .NET runtime in-process
 and guarantees reliability/scalabili...
User-Defined Operations
 CLR Supports User Defined Data
 types, functions, aggregates and table valued
 functions
 Scalar ...
TVF and UDA with SQL CLR
Filestream storage
 Storing large binary objects in databases is
 suboptimal
    Large objects take buffers in database me...
SQL Server 2008 Filestream
 A filegroup for filestream storage is declared using
 DDL
    Filestream storage is tied to a ...
Programming with Filestreams
 Filestream columns are available with SQL
 methods
    If SQL is used, indistinguishable fro...
FileStream in SQL
Hierarchical Data
 Hierarchical data consists of nodes and edges
 Hierarchical data can be modeled in relational
 as
    A...
SQL Server and Hierarchical Data
 SQL Server 2005 adds Native Hierarchical
 Queries
    Recursive common table expression
...
SQL Server and Hierarchical Data
 In SQL 2008, new Built-In Data Type -
 HierarchyID
 SQLCLR based system UDT
    Useable ...
Working with HierarchyID
 Nodes can be added with serializable transaction
 After computing last child
      UPDATE Org
  ...
Uisng the HierarchyID
Spatial Data
 Spatial data provides answers to location-based
 queries
    Which roads intersect the Microsoft campus?
   ...
SQL Server 2008 and Spatial Data
 SQL Server supports two spatial data types
    GEOMETRY - flat earth model
    GEOGRAPHY...
GEOGRAPHY Requirements
 GEOGRAPHY type has additional requirements
 Coordinate order is Latitude/Longitude
    This will b...
Sample Query
Which roads intersect Microsoft’s main campus?




SELECT * FROM roads WHERE roads.geom.STIntersects(@ms)=1
Working with Spatial Data
Beyond relational?
Making sense of your data
  SQL Server stores relational and non-relational
  data
     XML and CLR sup...
Related Content
Breakout Sessions (session codes and titles)



Interactive Theater Sessions (session codes and titles)


...
Track Resources
Resource 1



Resource 2



Resource 3



Resource 4
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be...
Dev Sql Beyond Relational
Dev Sql Beyond Relational
Dev Sql Beyond Relational
Upcoming SlideShare
Loading in …5
×

Dev Sql Beyond Relational

766 views
705 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
766
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Dev Sql Beyond Relational

  1. 1. Praveen Srivatsa Director, AsthraSoft Consulting Microsoft Regional Director, Bangalore Session Code:
  2. 2. Why beyond relational? SQL support for non-relational data A large part of the world’s data is non-relational. Think Emails, 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 scenarios Attachments, free text documents, notes, images Medical/Scientific data Geo spatial, location aware data
  3. 3. SQL Server 2005 and XML data Native XML data type XML Schema support in database Mapping of SQL Server types to XSD types XQuery support Exposed as methods on XML data type XQuery strings are input to these methods XML Indexes Many improvements to SELECT...FOR XML XML input from file system through BULK data provider .NET XML APIs available through SQLCLR SQLXML functionality ships with database SSIS supports XML input through adapter
  4. 4. SQL Server 2008 XML Enhancements Mapping of new date/time data types to XSD types Support for more XML Schema constructs Union and list types Many industry-standard XSD schemas use this Lax validation of xsd:any wildcards Office documents and other XSD schemas use this XQuery support for 'let' clause in FLWOR expressions XML DML supports insert of XML data type
  5. 5. Using XML in SQL Server
  6. 6. Reliability, Scalability, and Security SQL Server loads the .NET runtime in-process and guarantees reliability/scalability/security .NET 2.0 hosting APIs allow host control All .NET resources managed and tracked by SQL Server .NET 2.0 libraries must be safe to run in SQL Server System assemblies divided into 'safe' and 'unsafe' User code divided into three classifications Safe - in process calls only, code is reliable External - some out of process calls, code is reliable Unsafe - all out of process, reliability not guaranteed
  7. 7. User-Defined Operations CLR Supports User Defined Data types, functions, aggregates and table valued functions Scalar UDFs without data access is where .NET excels SQL Server 2008 include types exposed using SQLCLR HierarchyID Geography Geometry
  8. 8. TVF and UDA with SQL CLR
  9. 9. Filestream storage Storing large binary objects in databases is suboptimal Large objects take buffers in database memory Large objects cause database fragmentation In file system however, quot;updatequot; is delete and insert quot;Before imagequot; in an update is not deleted immediately Storing all related data in a database adds Transactional consistency Integrated, point-in-time backup and restore Single storage and query vehicle
  10. 10. SQL Server 2008 Filestream A filegroup for filestream storage is declared using DDL Filestream storage is tied to a database The filegroup is mapped to a directory Must be NTFS file system Caution: Files deleteable from file system if you have appropriate permissions VARBINARY(MAX) columns can be defined with FILESTREAM attribute Table must also have UNIQUEIDENTIFIER column Filestream storage not available for other large types Data is stored in the file system
  11. 11. 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 name Acquire context with GET_FILESTREAM_TRANSACTION_CONTEXT Use OpenSqlFilestream to get a file handle
  12. 12. FileStream in SQL
  13. 13. Hierarchical Data Hierarchical data consists of nodes and edges Hierarchical data can be modeled in relational as Adjacency model - separate column for edge Most common, column can either be in same or separate table Path Enumeration model - column w/hierarchical path Nested Set model - adds quot;leftquot; and quot;rightquot; columns to represent edges, which must be maintained separately
  14. 14. SQL Server and Hierarchical Data SQL Server 2005 adds Native Hierarchical Queries Recursive common table expression ANSI-standard Hierarchical Data can be modeled as XML XML data type uses ORDPATH format to store elements, attributes and hierarchical constructs Variable length to 900 bytes Comparable type - can be used as index key
  15. 15. SQL Server and Hierarchical Data In SQL 2008, new Built-In Data Type - HierarchyID SQLCLR based system UDT Useable on .NET clients directly as SqlHierarchyId An implementation of path enumeration model Uses ORDPATH internally for speed
  16. 16. Working with HierarchyID Nodes can be added with serializable transaction After computing last child UPDATE Org SET @last_child = LastChild = EmployeeId.GetDescendant(LastChild,NULL) WHERE EmployeeId = @mgrid INSERT Org (EmployeeId, EmployeeName) VALUES(@last_child, @EmpName) Node can be added with error detection BEGIN INS_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
  17. 17. Uisng the HierarchyID
  18. 18. 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 database If your database includes an address
  19. 19. SQL Server 2008 and Spatial Data SQL Server supports two spatial data types GEOMETRY - flat earth model GEOGRAPHY - round earth model Both types support all of the instanciable OGC types InstanceOf method can distinguish between them Supports two dimension data X and Y or Lat and Long members Z member - elevation (user-defined semantics) M member - measure (user-defined semantics)
  20. 20. GEOGRAPHY Requirements GEOGRAPHY type has additional requirements Coordinate 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
  21. 21. Sample Query Which roads intersect Microsoft’s main campus? SELECT * FROM roads WHERE roads.geom.STIntersects(@ms)=1
  22. 22. Working with Spatial Data
  23. 23. Beyond relational? Making sense of your data SQL Server stores relational and non-relational data XML and CLR support improves with each release Filestream storage stores BLOBs on file system Buffer, fragmentation savings Spatial data has Library of spatial functions Three standard input and output formats Design all the data for your applications and choose the right model to deploy the data.
  24. 24. 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)
  25. 25. Track Resources Resource 1 Resource 2 Resource 3 Resource 4
  26. 26. © 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.

×