• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Sql Summit   Clr, Service Broker And Xml
 

Sql Summit Clr, Service Broker And Xml

on

  • 4,127 views

Presentation from the SQL Summit in Grand Rapids for the launch of SQL Server 2005

Presentation from the SQL Summit in Grand Rapids for the launch of SQL Server 2005

Statistics

Views

Total Views
4,127
Views on SlideShare
4,123
Embed Views
4

Actions

Likes
0
Downloads
75
Comments
1

1 Embed 4

http://www.slideshare.net 4

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • 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 :)
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Sql Summit   Clr, Service Broker And Xml Sql Summit Clr, Service Broker And Xml Presentation Transcript

  •  
  • SQL Server 2005 for Developers David Truxall NuSoft Solutions Drew Robbins Microsoft Corporation
  • Agenda
    • XML Enhancements
    • CLR in SQL Server
    • Service Broker
  • 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
  • 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.
  • 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
  • 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()
  • 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
  • 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
  • XML Data Type
  • 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
  • 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;]
  • 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
  • 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
  • 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]')
  • XQuery
  • 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
  • CLR in the Database Overview
    • Enhanced programming model
    • Enhanced safety and security
    • User defined types and aggregates
    • Common development environment
    • Performance and scalability
  • 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)
  • 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
  • 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
  • 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
  • CLR in the Database Security
    • Permission Sets
      • SAFE
      • EXTERNAL_ACCESS
      • UNSAFE
  • 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
  • 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)
  • 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);
        • }
  • 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;;
  • 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);
        • }
  • 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
  • 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()
  • 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
  • CLR in the Database
  • 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
  • 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
  • Service Broker Asynchronous Architecture
    • Loose coupling
    • Load distribution
    • Batch processing
    • Performance
    • Scale out
  • Service Broker Order Entry Data Flow Diagram
  • 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
  • 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
  • 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
  • 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
  • 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
  • Service Broker Impact on Performance Shipping as trigger during Order Shipping queued by trigger during Order
  • Service Broker
    • Demo Scenario
    OrderService ShippingService AccountsService NewOrder
  • Service Broker
  • 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.
  • Call To Action http://www.chrysalisevents.com/vs2005devcon/ Detroit – June 16
  • © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.