Sql Summit Clr, Service Broker And Xml

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

  • + mehmetcihangir Mehmet Cihangir 7 months ago
    Great work thanks....
    btw u should use dev \ efor -the Visual Studio plug-in that helps you monitor your development progres- http://www.devefor.com , u can download it free :)
Post a comment
Embed Video
Edit your comment Cancel

Favorites, Groups & Events

Sql Summit Clr, Service Broker And Xml - Presentation Transcript

  1.  
  2. SQL Server 2005 for Developers David Truxall NuSoft Solutions Drew Robbins Microsoft Corporation
  3. Agenda
    • XML Enhancements
    • CLR in SQL Server
    • Service Broker
  4. XML in the Database Overview
    • XML has become widely adopted
    • XML is ubiquitous, extensible, and a platform independent transport format
    • Supports structured and semi-structured data
    • Limited support in SQL Server 2000
    • First class support in SQL Server 2005
  5. XML In the Database Business Opportunity
    • The majority of all data transmitted electronically between organizations is now in XML.
    • By storing XML natively, SQL Server 2005 helps eliminate the friction of data transfer between organizations.
    • With the improved XML support in VS 2005, building e-business applications is radically simplified.
  6. XML in the Database XML Data Type
    • SQL Server 2005 adds native XML storage with XML data type
    • Stores both well-formed and validated XML
    • Implementation
      • Markup documents
      • Tree-structured data where re-assembly costs should be minimal
      • Semi-structured data
  7. XML in the Database XML Data Type
    • An alternative to storing XML on disk
    • Supports column, variable, or parameter
    • Can represent Version 1.0 documents or fragments
    • Methods on XML data type
      • query(), value(), exist(), modify(), and nodes()
  8. XML in the Database XML Schema Support
    • Validation and typing provided by XSD
      • W3C recommendation
      • Mechanism for type definitions
      • Validation constraints
    • Typed Data
      • Guarantees the shape of the data
      • Allows storage and query optimizations
  9. XML in the Database XML Schema Collections
    • Creating an XML Schema Collection
      • CREATE XML SCHEMA COLLECTION ResumeSchema AS
      • '<xs:schema
      • targetNameSpace='http://schemas.ms.com/emp&quot; …/>'
    • Constraining XML documents
      • CREATE TABLE Employee (..., Resume XML(ResumeSchema))
    • Retrieving XML Schema Collections
      • SELECT Name
      • FROM AdventureWorks.sys.xml_schema_collections
  10. XML Data Type
  11. XML in the Database XML Indexes
    • Create XML index on XML column
      • CREATE PRIMARY XML INDEX IDX1 ON JobCandidate (Resume)
    • Creates a secondary, B-tree index on
      • Path, Property, or Value
    • Speeds up queries
      • Results can be served directly from index
      • Uses SQL Server's cost based optimizer
    • Full-Text Indexing/Searching supports XML
  12. XML in the Database XML Indexes
    • PATH Index
      • When querying by path and value
      • /ItemList/Item[@ProductID=&quot;1&quot;]
    • PROPERTY Index
      • When retrieving node values by path
      • (/ItemList/Item/@ProductID)[1]
    • VALUE Index
      • When querying imprecisely, like for existence
      • //Item[@ProductID=&quot;1&quot;]
  13. XML in the Database XML Indexes
    • Requirements
      • A clustered PK must exist in the table
      • If XML index exists, the PK may not be altered
      • Only one primary XML index per column
      • Many secondary XML indexes per column
        • PATH, PROPERTY, and VALUE
      • All index names must be unique per table
  14. XML in the Database XQuery
    • Query XML documents and data
      • Based on W3C working draft
      • FLWOR - For, Let, Where, Order by, Return
    • XQuery methods
      • .query() – returns XML data type instance
      • .value() – returns a single (scalar) value
      • .exist() – returns 1 if expression returns item(s)
      • .nodes() – returns a row per selected node
  15. XML in the Database XML Data Manipulation Language
    • Inefficient to UPDATE the entire column
    • XML sub-tree modification using .modify()
      • Three actions: Insert , Delete , or Replace
      • UPDATE xmlTable SET xmlColumn.modify('insert
      • <section num=&quot;2&quot;>
      • <heading>Background</heading>
      • </section>
      • after (/doc/section[@num=1])[1]')
  16. XQuery
  17. XML in the Database FOR XML Improvements
    • Support for XSD schemas
    • Support for NULL values
    • Support for XML data type
    • Nested FOR XML
    • Can be assigned to an XML data type
    • FOR XML PATH
  18. CLR in the Database Overview
    • Enhanced programming model
    • Enhanced safety and security
    • User defined types and aggregates
    • Common development environment
    • Performance and scalability
  19. CLR in the Database Business Opportunity
    • Leverage .NET productivity and the BCL
    • Better way to encapsulate your IP
    • A new world of ways to extend SQL Server
      • User-defined types to fit your domain
      • User-defined aggregates to fit your domain
    • Go over the wall you hit with T-SQL
    • Replace Extended Procedures (XPs)
  20. CLR in the Database Architecture
    • Common Language Runtime (CLR) Assemblies
      • Can write stored procedures, triggers, UD functions, UD types, and aggregate functions
      • Any CLR language
      • Great replacement for Extended Stored Procedures (XPs)
    • Supported in SQL Express
  21. CLR in the Database Microsoft® SQL Server™ Runtime hosted inside SQL Microsoft® Visual Studio® .NET Project VB, C# SQL Queries: select sum( tax(sal,state) ) from Emp where county = ‘King’ Assembly: “TaxLib.dll” build SQL Data Definition: create assembly … create function … create procedure … create trigger … create type … deploy
  22. CLR in the Database Security
    • Managed Code running in CLR
      • Type safety, application domains, CAS
      • More secure than XPs
    • Reliability and safety design goals
      • User code can't compromise SQL engine
      • User code can't overwrite SQL engine memory buffers or internal data structures
      • User code must be authenticated and authorized before being allowed access
  23. CLR in the Database Security
    • Permission Sets
      • SAFE
      • EXTERNAL_ACCESS
      • UNSAFE
  24. CLR in the Database T-SQL or Managed Code?
    • T-SQL is superior when
      • Code mostly performs data access
      • Code has little or no procedural logic
    • Managed Code is superior when
      • Code has CPU-intensive methods
      • Code has complex logic
      • Code can make use of the .NET BCL
  25. CLR in the Database Managed Database Objects X Aggregate Functions X User Defined Types X X User Defined Functions X X Triggers X X Stored Procedures .NET (SQL 2005) T-SQL (SQL 2000)
  26. CLR in the Database Managed Stored Procedures
    • Stored Procedures
      • Public, static methods on a class
      • Returns a void or int
      • SqlPipe.Execute() and SqlPipe.Send()
        • public static void ExecuteToClient() { SqlConnection conn = new SqlConnection(&quot;context connection=true&quot;);
        • SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = &quot;select @@version&quot;; SqlContext.GetPipe().Execute(cmd);
        • }
  27. CLR in the Database Managed Triggers
    • Triggers
      • Similar to stored procedures
      • Determine which columns have been modified
      • Reference INSERTED and DELETED tables
      • SqlConnection conn = new SqlConnection(&quot;context connection=true&quot;);
        • sqlCommand sqlComm = conn.CreateCommand()
        • sqlComm.CommandText = &quot;SELECT column_1 from INSERTED&quot;;
  28. CLR in the Database Managed User Defined Functions
    • Two types of User Defined Functions
      • Scalar-valued function (SVF)
        • Returns a single value, such as string or integer
        • Class methods determine return type
      • Table-valued function (TVF)
        • Data returned through an ISqlReader object
        • public static ISqlReader ReadLog(String logname) {
        • return (ISqlReader)new MySqlReader(logname);
        • }
  29. CLR in the Database Managed User Defined Types
    • When the built-in SQL Server types won't do
      • Create custom, complex structured types
      • Benefits
        • Strong encapsulation (both at client and server)
        • Deep integration support with SQL Server
      • Requirements
        • SqlUserDefinedTypeAttribute, Serializable, INullable, Parse(), ToString()
        • Read() and Write() to support custom serialization
        • Others
  30. CLR in the Database Managed Aggregate Functions
    • Perform a calculation on a set of values and return a single value, such as SUM or MAX
      • SqlUserDefinedAttribute
      • Must implement these methods so the Query Processor can use your aggregate function
        • Init(), Accumulate(), Merge(), Terminate()
  31. CLR in the Database Assemblies
    • .NET Assemblies
      • Self-describing, metadata, dependencies
      • Unit of deployment, CLR permission grants, versioning, etc.
      • Stored in database
    • CREATE, ALTER, DROP DDL
      • CREATE ASSEMBLY FinanceFunctions FROM 'c:codeFinanceFunctions.dll' WITH PERMISSION_SET = SAFE
  32. CLR in the Database
  33. Service Broker Overview
    • Service Broker adds asynchronous, distributed, and decoupled environment
      • Fully integrated into database engine
      • New set of SQL Server objects (DDL & DML)
      • Integrated management and deployment
    • Custom solutions and benefits
      • Generalized asynchronous semantics
      • Inter and intra-instance queuing
        • Distributed transactions not required
      • Multi-threading in stored procedures
  34. Service Broker Business Opportunity
    • Don't call us, we'll call you
    • Asynch can result in faster applications
    • Asynch can smooth out connectivity bugs
    • Notifications can help w/ middle-tier or client caching of data
    • Leverage Message Queue architecture
    • Shares Begin/End patterns with .NET
  35. Service Broker Asynchronous Architecture
    • Loose coupling
    • Load distribution
    • Batch processing
    • Performance
    • Scale out
  36. Service Broker Order Entry Data Flow Diagram
  37. Service Broker Features
    • Database objects and DML statements that enable asynchronous messaging operations
      • Queues, Message Types, Contracts, Services
      • “ BEGIN DIALOG”, “SEND”, “RECEIVE”
    • Fully integrated into the database engine
      • Single Programming Model
      • Local Transactions
      • Integrated Management and Deployment
  38. Service Broker
    • Both the client & stored procedure run in:
    • Same Transaction
    • Same Security Context
    • Same Thread of Execution
    Client App SQL Engine Stored Proc Without Service Broker Transaction
  39. Service Broker Client App Launched Stored Proc
    • Stored proc runs on:
    • Different transaction
    • Different thread
    • Different security
    • Different time
    With Service Broker Transaction Transaction Persisted Dialog
  40. Service Broker Dialogs
    • Two-way Messaging “Dialogs”
      • Exactly-once, In-order
      • Reliable delivery to local and remote queues
      • Large Message Fragmentation
    APP 1 SQL Engine SQL Engine APP 2
  41. Service Broker New Commands
      • CREATE MESSAGE TYPE
      • CREATE CONTRACT
      • CREATE QUEUE
      • CREATE SERVICE
      • ALTER SERVICE
      • ALTER MESSAGE TYPE
      • ALTER QUEUE
      • ALTER CONTRACT
      • DROP MESSAGE TYPE
      • DROP CONTRACT
      • DROP QUEUE
      • DROP SERVICE
      • CREATE ROUTE
      • ALTER ROUTE
      • DROP ROUTE
    New DDL BEGIN DIALOG CONVERSATION END CONVERSATION MOVE CONVERSATION GET SERVICE INSTANCE RECEIVE SEND BEGIN DIALOG TIMER New DML
  42. Service Broker Impact on Performance Shipping as trigger during Order Shipping queued by trigger during Order
  43. Service Broker
    • Demo Scenario
    OrderService ShippingService AccountsService NewOrder
  44. Service Broker
  45. Call To Action
    • Leverage SQL Server 2005 to connect with applications and partners using the ubiquitous XML format.
    • Be smart about building functionality using CLR in SQL Server.
    • Leverage the Service Broker to create loosely-coupled message queues for your applications.
  46. Call To Action http://www.chrysalisevents.com/vs2005devcon/ Detroit – June 16
  47. © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.

+ David TruxallDavid Truxall, 2 years ago

custom

1547 views, 0 favs, 0 embeds more stats

Presentation from the SQL Summit in Grand Rapids fo more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 1547
    • 1547 on SlideShare
    • 0 from embeds
  • Comments 1
  • Favorites 0
  • Downloads 50
Most viewed embeds

more

All embeds

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories