2.2 SQL Server 2005 的 XML 支援功能. Overview XML Enhancements in SQL Server 2005 The xml Data Type Using XQuery.

Slides:



Advertisements
Similar presentations
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Advertisements

Paper by: A. Balmin, T. Eliaz, J. Hornibrook, L. Lim, G. M. Lohman, D. Simmen, M. Wang, C. Zhang Slides and Presentation By: Justin Weaver.
Chapter 9: Advanced SQL and PL/SQL Topics Guide to Oracle 10g.
The XML data type in Microsoft SQL Server. The XML Type Microsoft SQL Server offers a special data type – XML – Used in tables, etc. – Basically a (long)
Storing and Querying Ordered XML Using a Relational Database System By Khang Nguyen Based on the paper of Igor Tatarinov and Statis Viglas.
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
2 Copyright © 2004, Oracle. All rights reserved. Creating Stored Functions.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Module 9 Designing an XML Strategy. Module 9: Designing an XML Strategy Designing XML Storage Designing a Data Conversion Strategy Designing an XML Query.
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
Working with SQL and PL/SQL/ Session 1 / 1 of 27 SQL Server Architecture.
Indexing XML Data Stored in a Relational Database VLDB`2004 Shankar Pal, Istvan Cseri, Gideon Schaller, Oliver Seeliger, Leo Giakoumakis, Vasili Vasili.
SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
XMLII XSchema XSchema XQuery XQuery. XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports XML.
19 – 21 MARCH 2006 Riyadh, Saudi Arabia. XML and Web Services support in SQL Server 2005 Michael Storey Xpertise Training Ltd (UK)
Module 17 Storing XML Data in SQL Server® 2008 R2.
Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.
Integrating XML with Microsoft SQL Server ©NIITeXtensible Markup Language/Lesson 9/Slide 1 of 31 Objectives In this lesson, you will learn to: * Generate.
XML, CFMX CFML & SQL XML Kevin Penny, MMCP
Using XML in SQL Server 2005 NameTitleCompany. XML Overview Business Opportunity The majority of all data transmitted electronically between organizations.
XML in SQL Server Overview XML is a key part of any modern data environment It can be used to transmit data in a platform, application neutral form.
Introduction to Databases Chapter 7: Data Access and Manipulation.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
XML Overview. Chapter 8 © 2011 Pearson Education 2 Extensible Markup Language (XML) A text-based markup language (like HTML) A text-based markup language.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Sofia, Bulgaria | 9-10 October Using XQuery to Query and Manipulate XML Data Stephen Forte CTO, Corzen Inc Microsoft Regional Director NY/NJ (USA) Stephen.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
5/24/01 Leveraging SQL Server 2000 in ColdFusion Applications December 9, 2003 Chris Lomvardias SRA International
Objectives In this lesson, you will learn to: *Identify the need for ADO.NET *Identify the features of ADO.NET *Identify the components of the ADO.NET.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Exam and Lecture Overview.
Module 18 Querying XML Data in SQL Server® 2008 R2.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Copyright© 2005 Oracle Corp.1 SQL/XML Jim Melton USA: Oracle Corp. JTC1 SC32N1632.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
Session 11 Creating Tables and Using Data Types. RDBMS and Data Management/Session 11/2 of 40 Session Objectives Define the data types and list the categories.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
XML and Database.
SQL Server 2012 Session: 1 Session: 8 Accessing Data Data Management Using Microsoft SQL Server.
Dynamic SQL. 2 home back first prev next last What Will I Learn? Recall the stages through which all SQL statements pass Describe the reasons for using.
Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures.
SQL Server 2005: Extending the Type System with XML.
Chapter 14 1 Chapter 14 Storing and Retrieving XML in SQL Server 2000 November 6, 2001 Sook-Kyo Kwon.
Session 1 Module 1: Introduction to Data Integrity
Module 3: Using XML. Overview Retrieving XML by Using FOR XML Shredding XML by Using OPENXML Introducing XQuery Using the xml Data Type.
DAT 405 Extreme SqlXml Irwin Dolobowsky Program Manager – SqlXml Microsoft Corporation.
DML Statements contd.. SQL Server CURSORS Cursor is used in handling results of select query for data calculations Cursors are used as buffered.
XML Extensible Markup Language
Stored Procedures and Functions Pemrograman Basis Data MI2183.
11 Copyright © 2004, Oracle. All rights reserved. Managing XML Data in an Oracle 10g Database.
XML and SQL Server Better friends than you thought Matt Hartman.
Pure XML Pertemuan 10 Matakuliah: T0413 Tahun: 2009.
Module 9: Implementing Functions. Overview Creating and Using Functions Working with Functions Controlling Execution Context.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
6 Copyright © 2009, Oracle. All rights reserved. Using Dynamic SQL.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Trigger used in PosgreSQL
XML: Extensible Markup Language
Using XML in SQL Server and Azure SQL Database
Dirt, Spit, and Happy FLWOR
PROC SQL, Overview.
Overview Implementing Triggers Implementing XML Schemas.
Using Table Expressions
2/18/2019.
CPSC-608 Database Systems
XML? What’s this doing in my database? Adam Koehler
Presentation transcript:

2.2 SQL Server 2005 的 XML 支援功能

Overview XML Enhancements in SQL Server 2005 The xml Data Type Using XQuery

Lesson: XML Enhancements in SQL Server 2005 Enhancements to the FOR XML Clause Enhancements to the OPENXML Function

Enhancements to the FOR XML Clause EnhancementDescription ELEMENTS directive in RAW mode RAW mode queries can return element-centric XML. Support for NULL values Element-centric results can include empty elements for null values. Inline XSD schemas You can generate inline XSD schemas. TYPE directive returns results as xml data type Results from FOR XML queries can be xml values, making nested queries possible. PATH mode You can use XPath-like expressions to define XML results. ROOT directive You can specify a root element for your results. Named Element You can specify a named element for RAW and PATH mode queries.

Practice: Using the FOR XML Clause In this practice, you will: Return elements in RAW mode Return NULL values Return an inline XSD schema Use the TYPE directive Use PATH mode Use the ROOT directive Return named elements in a RAW mode query

Enhancements to the OPENXML Function EnhancementDescription Documents can be xml data type values The sp_xml_preparedocument stored procedure accepts xml parameters. Support for xml data type in the WITH clause Columns of type xml can be returned in the WITH clause. Batch-level scoping Document handles are scoped at the batch level and are released when the batch is completed.

Practice: Using the OPENXML Function In this practice, you will execute the OPENXML function

Lesson: The xml Data Type Storing XML in the Database How to Use Untyped XML How to Manage XML Schemas How to Use Typed XML How to Manage XML Indexes

Storing XML in the Database Benefits: Single store for structured and semistructured data Define variable content in a relational model Choose the most appropriate data model Single store for structured and semistructured data Define variable content in a relational model Choose the most appropriate data model Functionality: XML Indexes XQuery-based data retrieval XQuery-based modifications XML Indexes XQuery-based data retrieval XQuery-based modifications XML schema support: Typed XML: Validated by a schema Untyped XML: Nonvalidated XML Typed XML: Validated by a schema Untyped XML: Nonvalidated XML

How to Use Typed XML Declare a typed column or variable CREATE TABLE HumanResources.EmployeeResume (EmployeeID int, Resume xml (cvSchemas)) CREATE TABLE HumanResources.EmployeeResume (EmployeeID int, Resume xml (cvSchemas)) INSERT INTO HumanResources.EmployeeResume VALUES (1, '... ') INSERT INTO HumanResources.EmployeeResume VALUES (1, '... ') Assign typed XML (must conform to schema) Use CONTENT or DOCUMENT to allow/disallow fragments CREATE TABLE HumanResources.EmployeeResume (EmployeeID int, Resume xml (DOCUMENT cvSchemas)) CREATE TABLE HumanResources.EmployeeResume (EmployeeID int, Resume xml (DOCUMENT cvSchemas))

Lesson: Using XQuery What Is XQuery? How to Query XML with xml Data Type Methods How to Modify XML with the modify Method How to Shred XML to Relational Format with the Nodes Method

What Is XQuery? Describe the XML nodes to be retrieved Syntax includes and extends XPath 2.0 Based on working draft of W3C XQuery 1.0 language Specification ( Consist of two main sections:  Prolog – Namespace declare and schema imported  Body – XQuery expression specify the data to be retrieved

Martin Gudgin 33 short Simon Horrell 40 short Mark Szolkowski 30 medium Sample input XML document; people.xml

XQuery FLWOR Expressions FOR LET (not supported by SQL Server 2005) WHERE ORDER BY RETURN Using XQuery with the XML data type Methods  xml.exist  xml.value  xml.query  xml.nodes  xml.modify Updating the XML data type with XQuery DML

XQuery Expressions XQuery is a superset of XPath (: this is a valid XQuery :) /people/person[age > 30] (: so is this FLWOR expression :) for $p in /people/person where $p/age > 30 order by $p/age[1] return $p/name

Order by clause XQuery can easily sort by using order by  similar to SQL ORDER BY clause  must resolve to a scalar value nodesets not comparable

XQuery FLWOR Expressions FOR LET (not supported by SQL Server 2005) WHERE ORDER BY RETURN Using XQuery with the XML data type Methods  xml.exist  xml.value  xml.query  xml.nodes  xml.modify Updating the XML data type with XQuery DML

SQL Server 2005 Support Method of XQuery XQuery is supported through methods on the XML type  xml.exist - returns bool  xml.value - returns scalar  xml.query - returns XML data type instance  xml.nodes - returns one column rowset w/XML column  xml.modify - modifies an instance These methods can return  columns in rowsets - when used with SQL SELECT  variables

How to Query XML with xml Data Type Methods SELECT xmlCol.value( 'int') SELECT xmlCol.value( 'int') Use the value method

Using xml.exist -- pdoc must have a person element -- as a child of the people root CREATE TABLE xmltab( id INTEGER PRIMARY KEY, pdoc XML CHECK (pdoc.exist('/people/person')=1) ) -- ok insert xmltab values( 1, ' ') -- fails, no persons insert xmltab values( 2, ' ')

How to Modify XML with the modify Method 'insert element salesperson {"Bill"} as first into (/InvoiceList/Invoice)[1]') 'insert element salesperson {"Bill"} as first into (/InvoiceList/Invoice)[1]') SET xmlCol.modify( replace value of (/InvoiceList/Invoice/SalesPerson/text())[1] with "Ted"') SET xmlCol.modify( replace value of (/InvoiceList/Invoice/SalesPerson/text())[1] with "Ted"') 'delete (/InvoiceList/Invoice/SalesPerson)[1]') 'delete (/InvoiceList/Invoice/SalesPerson)[1]') Use the insert statement Use the replace statement Use the delete statement