Retrieving XML Data from SQL server.  Using the FOR XML Clause to Retrieve Data Retrieving Data in XML Format How SQL Server Generates XML Using the.

Slides:



Advertisements
Similar presentations
2/23/05 CS Advanced Databases 1 XML Support in SQL Server 2000 Sriram Krishnan Kevin Menard.
Advertisements

XML: Extensible Markup Language
Module 6: Working with Subqueries. Overview Introduction to Subqueries Using a Subquery as a Derived Table Using a Subquery as an Expression Using a Subquery.
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
Inside Data Access with SQLXML: Architecture Guide Rolandas Gricius MCT, MCSE, MCSD Adapted From.
XML Views El Hazoui Ilias Supervised by: Dr. Haddouti Advanced XML data management.
1 COS 425: Database and Information Management Systems XML and information exchange.
1 Storing XML using Relational Model XML and data management By: Habiba Skalli For: Dr. Haddouti.
SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence.
Viewing relational data as XML Using Microsoft SQL Server.
Using SQL Queries to Generate XML- Formatted Data Joline Morrison Mike Morrison Department of Computer Science University of Wisconsin-Eau Claire.
DAT304 Leveraging XML and HTTP with Sql Server Irwin Dolobowsky Program Manager Webdata Group.
2.2 SQL Server 2005 的 XML 支援功能. Overview XML Enhancements in SQL Server 2005 The xml Data Type Using XQuery.
SQL Joins.
Integrating XML with Microsoft SQL Server ©NIITeXtensible Markup Language/Lesson 9/Slide 1 of 31 Objectives In this lesson, you will learn to: * Generate.
Rationale Aspiring Database Developers should be able to efficiently query and maintain databases. This module will help students learn the Structured.
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.
XML 과 SQL Server 2000 에서 지원하는 XML 처리 방법 정 홍주 WebTime Feelanet.
Introduction to Accounting Information Systems
Module 14: WCF Send Adapters. Overview Lesson 1: Introduction to WCF Send Adapters Lesson 2: Consuming a Web Service Lesson 3: Consuming Services from.
SQL/lesson 2/Slide 1 of 45 Retrieving Result Sets Objectives In this lesson, you will learn to: * Use wildcards * Use the IS NULL and IS NOT NULL keywords.
Basic SQL. Implementation Schemes: Once we have a set of relation schemes, we can translate them into implementation schemes. We use to express implementation.
Chapter 9 Joining Data from Multiple Tables
1 Joining Tables in Queries. 2 Objectives You will be able to Write SQL queries that use Join operations to retrieve information from multiple tables.
5/24/01 Leveraging SQL Server 2000 in ColdFusion Applications December 9, 2003 Chris Lomvardias SRA International
JOINS cis 407 Inner join Right and left outer join Full join Cross join.
1 Design Issues in XML Databases Ref: Designing XML Databases by Mark Graves.
Module 18 Querying XML Data in SQL Server® 2008 R2.
[ Part III of The XML seminar ] Presenter: Xiaogeng Zhao A Introduction of XQL.
SQL ORACLE 1. Data Type 2 3 VARCHAR2(size [BYTE | CHAR]) Variable-length character string having maximum length size bytes or characters. Maximum size.
Advanced Data Modeling. Heterogeneous Mapping Heterogeneous Mapping is the ability of MSTR7 tools to join on unlike column names. Heterogeneous Mapping.
Chapter 14 1 Chapter 14 Storing and Retrieving XML in SQL Server 2000 November 6, 2001 Sook-Kyo Kwon.
SQLXML XML Technology For SQL Server Brian Moore Developer and Platform Strategy Group Microsoft Corporation.
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.
In this session, you will learn to: Query data by using joins Query data by using subqueries Objectives.
Drilling down Restrictions on data interaction between browser and server a new connection has to be made for each interaction Solution: break up the data.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
Module 2: Authoring Basic Reports. Overview Creating a Basic Table Report Formatting Report Pages Calculating Values.
Module 2: Querying and Filtering Data. Using the SELECT Statement Filtering Data Working with NULL Values Formatting Result Sets Performance Considerations.
SQL SERVER.   Optionally, some other XML 
XML Extensible Markup Language
 CONACT UC:  Magnific training   
C10. SQL-S + XML Date Semistructurate,
Slide 1 of 32ASH-Training Querying and Managing Data Using SQL Server 2014 By: Segla In this session, you will learn to: Query data by using joins Query.
DAT 400 Inside Data Access with SQLXML: Architecture Guide Alexander Vaschillo Lead Program Manager WebData XML Group Microsoft Corporation.
CFUNITED – The premier ColdFusion conference Beyond Basic SQL for CF Nate Nelson
Module 5: Working with Subqueries. Writing Basic Subqueries Writing Correlated Subqueries Comparing Subqueries with Joins and Temporary Tables Using Common.
IFS180 Intro. to Data Management Chapter 10 - Unions.
XML Databases Presented By: Pardeep MT15042 Anurag Goel MT15006.
Authoring for Performance
XML: Extensible Markup Language
More SQL: Complex Queries,
Using XML in SQL Server and Azure SQL Database
Connect to SQL Server and run select statements
Querying Multiple Tables
Data Virtualization Tutorial: JSON_TABLE Queries
SQL Server 2016 JSON Support FOR Data Warehousing
Sorting and Filtering Data
Querying Multiple Tables
06 | Using Subqueries and APPLY
20761B 12: Using Set Operators Module 12   Using Set Operators.
Implementing Data Models & Reports with Microsoft SQL Server
07 | Using Table Expressions
20761B 10: Using Subqueries Module 10   Using Subqueries.
Database.
Aggregations Various Aggregation Functions GROUP BY HAVING.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Lesson 5: HTML Tables.
Grouping and Aggregating Data
Presentation transcript:

Retrieving XML Data from SQL server

 Using the FOR XML Clause to Retrieve Data Retrieving Data in XML Format How SQL Server Generates XML Using the FOR XML Clause Using RAW Mode to Retrieve XML Using AUTO Mode to Retrieve XML Demo: Using RAW and AUTO

Retrieving Data in XML Format Purchase order HTML Retailer Supplier Web site XML Customer

How SQL Server Generates XML ROWSET TDS/ Token XML SELECT … FROM … WHERE … FOR XML MODE SELECT … FROM … WHERE … FOR XML MODE Query processor ROWSET to XML

Using the FOR XML Clause The FOR XML Clause Syntax XML Document Fragments SELECT select_list FROM table_source WHERE search_condition FOR XML RAW | AUTO | EXPLICIT [, XMLDATA] [, ELEMENTS] [, BINARY BASE64] SELECT select_list FROM table_source WHERE search_condition FOR XML RAW | AUTO | EXPLICIT [, XMLDATA] [, ELEMENTS] [, BINARY BASE64]

Using RAW Mode to Retrieve XML Generic element produced for each row returned by the query SELECT OrderID, OrderDate FROM Orders FOR XML RAW SELECT OrderID, OrderDate FROM Orders FOR XML RAW

Using AUTO Mode to Retrieve XML Table name(s) are used to name elements SELECT OrderID, OrderDate FROM Orders FOR XML AUTO SELECT OrderID, OrderDate FROM Orders FOR XML AUTO

Demonstration: Using RAW and AUTO

 Controlling XML Output Specifying the ELEMENTS Option Working with Multiple Tables Demo: Retrieving Data from Multiple Tables Specifying the XMLDATA Option Retrieving Binary Data

Specifying the ELEMENTS Option Columns are returned as child elements SELECT OrderID, OrderDate FROM Orders FOR XML AUTO, ELEMENTS SELECT OrderID, OrderDate FROM Orders FOR XML AUTO, ELEMENTS /04/ /05/ /04/ /05/1996

Working with Multiple Tables SELECT OrderForm.OrderID, Item.ProductID Item.Quantity FROM Orders OrderForm JOIN [Order Details] Item ON OrderForm.OrderID = Item.OrderID ORDER BY OrderForm.OrderID FOR XML RAW SELECT OrderForm.OrderID, Item.ProductID Item.Quantity FROM Orders OrderForm JOIN [Order Details] Item ON OrderForm.OrderID = Item.OrderID ORDER BY OrderForm.OrderID FOR XML RAW SELECT OrderForm.OrderID, Item.ProductID Item.Quantity FROM Orders OrderForm JOIN [Order Details] Item ON OrderForm.OrderID = Item.OrderID ORDER BY OrderForm.OrderID FOR XML AUTO SELECT OrderForm.OrderID, Item.ProductID Item.Quantity FROM Orders OrderForm JOIN [Order Details] Item ON OrderForm.OrderID = Item.OrderID ORDER BY OrderForm.OrderID FOR XML AUTO

Demonstration: Retrieving Data from Multiple Tables

Specifying the XMLDATA Option XML-Data Reduced (XDR) Schema pre-pended to results SELECT OrderID, OrderDate FROM Orders FOR XML AUTO, XMLDATA SELECT OrderID, OrderDate FROM Orders FOR XML AUTO, XMLDATA <Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft- com:datatypes"> <ElementType name="Orders" content="empty“ model="closed"> <Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft- com:datatypes"> <ElementType name="Orders" content="empty“ model="closed">

Retrieving Binary Data SELECT EmployeeID, Photo FROM Employees WHERE EmployeeID = 10 FOR XML AUTO SELECT EmployeeID, Photo FROM Employees WHERE EmployeeID = 10 FOR XML AUTO <Employees EmployeeID="1" <Employees EmployeeID="1" SELECT EmployeeID, Photo FROM Employees WHERE EmployeeID = 1 FOR XML AUTO, BINARY BASE64 SELECT EmployeeID, Photo FROM Employees WHERE EmployeeID = 1 FOR XML AUTO, BINARY BASE64 <Employees EmpID="1" Photo="FRwvAAIAAAANAA4AFAAhAP////9Ca..."/> <Employees EmpID="1" Photo="FRwvAAIAAAANAA4AFAAhAP////9Ca..."/>

 Generating Custom XML Formats Custom XML Formats Universal Tables Using EXPLICIT Mode Demonstration: Universal Tables and XML Using EXPLICIT Mode with Multiple Tables

Custom XML Formats Columns in a table that are mapped to an XML element can be represented as: Element values Attributes Child elements T00:00:00 Queso Cabrales Singaporean Fried Mee T00:00:00 Queso Cabrales Singaporean Fried Mee

Universal Tables Tabular representation of an XML document Tag and Parent columns determine hierarchy Column names determine element / attribute mapping TagParentInvoice!1!InvoiceNoInvoice!1!Date!ElementLineItem!2!ProductIDLineItem!2 1NULL T00:00:00NULL NULL11Queso Cabrales NULL42Singaporean …

Using EXPLICIT Mode Construct the Transact-SQL to generate the universal table Add the FOR XML EXPLICIT clause SELECT 1 AS Tag, NULL AS Parent, OrderID AS [Invoice!1!InvoiceNo], OrderDate AS [Invoice!1!Date!Element] FROM Orders WHERE OrderID = FOR XML EXPLICIT SELECT 1 AS Tag, NULL AS Parent, OrderID AS [Invoice!1!InvoiceNo], OrderDate AS [Invoice!1!Date!Element] FROM Orders WHERE OrderID = FOR XML EXPLICIT T00:00: T00:00:00

Using EXPLICIT Mode with Multiple Tables Use the UNION ALL operator to retrieve multiple Tag values SELECT 1 AS Tag, NULL AS Parent, OrderID AS [Invoice!1!InvoiceNo], OrderDate AS [Invoice!1!Date!Element], NULL AS [LineItem!2!ProductID], NULL AS [LineItem!2] FROM Orders WHERE OrderID=10248 UNION ALL SELECT 2 AS Tag,1 AS Parent, OD.OrderID, NULL, OD.ProductID, P.ProductName FROM [Order Details] OD JOIN Orders O ON OD.OrderID=O.OrderID JOIN Products P ON OD.ProductID = P.ProductID WHERE OD.OrderID=10248 ORDER BY [Invoice!1!InvoiceNo], [LineItem!2!ProductID] FOR XML EXPLICIT SELECT 1 AS Tag, NULL AS Parent, OrderID AS [Invoice!1!InvoiceNo], OrderDate AS [Invoice!1!Date!Element], NULL AS [LineItem!2!ProductID], NULL AS [LineItem!2] FROM Orders WHERE OrderID=10248 UNION ALL SELECT 2 AS Tag,1 AS Parent, OD.OrderID, NULL, OD.ProductID, P.ProductName FROM [Order Details] OD JOIN Orders O ON OD.OrderID=O.OrderID JOIN Products P ON OD.ProductID = P.ProductID WHERE OD.OrderID=10248 ORDER BY [Invoice!1!InvoiceNo], [LineItem!2!ProductID] FOR XML EXPLICIT

Demonstration: Universal Tables and XML

Best Practices Use RAW Mode for Aggregated Data Use AUTO Mode for Attribute-Centric or Element-Centric XML Use Aliases with AUTO and RAW to Name XML Elements and Attributes Use an ORDER BY Clause when Querying Multiple Tables Use EXPLICIT Mode for XML Documents Containing a Mix of Attribute-Centric and Element-Centric Mappings