Tài liệu Module 7: XML for SQL Tools ppt

40 475 0
Tài liệu Module 7: XML for SQL Tools ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Contents Overview 1 Modifying Data with Updategrams 2 Lab 7.1: Using Updategrams 17 Inserting XML Data with the Bulk Load Facility 22 Lab 7.2: Bulk Loading XML Data 31 Best Practices 34 Review 36 Module 7: XML for SQL Tools Information in this document is subject to change without notice. The names of companies, products, people, characters, and/or data mentioned herein are fictitious and are in no way intended to represent any real individual, company, product, or event, unless otherwise noted. Complying with all applicable copyright laws is the responsibility of the user. No part of this document may be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without the express written permission of Microsoft Corporation. If, however, your only means of access is electronic, permission to print one copy is hereby granted. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.  2001 Microsoft Corporation. All rights reserved. Microsoft, ActiveX, BackOffice, BizTalk, MSDN, MS-DOS, SQL Server, Visual Basic, Visual C++, Visual InterDev, Visual J++, Visual Studio, Windows, Windows Media, Windows NT, and Windows 2000 are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries. Other product and company names mentioned herein may be the trademarks of their respective owners. Module 7: XML for SQL Tools iii Instructor Notes This module provides students with an understanding of Updategrams and XML Bulk Load functionality provided in the XML for SQL Web Update. After completing this module, students will be able to:  Insert, delete, and update data by using Updategrams.  Load Extensible Markup Language (XML) data into SQL Server by using the XML Bulk Load facility. Materials and Preparation This section provides the materials and preparation tasks that you need to teach this module. Required Materials To teach this module, you need Microsoft ® PowerPoint ® file 2091a_07.ppt. Preparation Tasks To prepare for this module, you should:  Read all of the materials for this module.  Complete the labs. Presentation: 90 Minutes Lab: 45 Minutes iv Module 7: XML for SQL Tools Module Strategy Use the following strategy to present this module:  Modifying Data with Updategrams Point out that an Updategram is conceptually a specialized form of template. Emphasize the use of Updategrams to enable full data modification over HTTP in a SQLISAPI virtual directory–based application. This means that you can build a full data-enabled Web solution without any Active Server Pages (ASP) code.  Inserting XML Data with the Bulk Load Facility Emphasize that when inserting large volumes of data into SQL Server tables the Bulk Load facility is more efficient than OpenXML. This is because the Bulk Load facility reads data as a stream, allowing inserts to begin before the entire XML document has been read. Module 7: XML for SQL Tools 1 Overview  Modifying Data with Updategrams  Inserting XML Data with the Bulk Load Facility ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** In this module, you will learn how to use Updategrams to modify data, and how to use the XML Bulk Load facility. After completing this module, you will be able to:  Insert, delete, and update data by using Updategrams.  Load Extensible Markup Language (XML) data into SQL Server by using the XML Bulk Load facility. To enable support for Updategrams and XML bulk load functionality in SQL Server 2000, you must download and install XML for SQL Web Update from the MSDN ® Web site at http://msdn.microsoft.com Topic Objective To provide an overview of the module topics and objectives. Lead-in In this module, you will learn about the additional functionality available in the XML for SQL Web Update. For Your Information You can download the XML for SQL Web Update from the MSDN Web site at http://msdn.microsoft.com 2 Module 7: XML for SQL Tools    Modifying Data with Updategrams  Using an Updategram to Modify Data  Structure of an XML Updategram  Mapping Updategram Values to SQL Data  Inserting Data with an Updategram  Deleting Data with an Updategram  Updating Data with an Updategram  Using Parameters with an Updategram  Using Updategrams from a Client Application ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** In this section, you will see how to use Updategrams to insert, update, and delete data in a Microsoft ® SQL Server ™ 2000 database. Topic Objective To introduce the topics in this section. Lead-in In this section, we will discuss the use of Updategrams to insert, delete, and update data. Module 7: XML for SQL Tools 3 Using an Updategram to Modify Data Shipping Co. Supplier INSERT UPDATE DELETE XML delivery data ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** Similar to template files, Updategrams are XML documents that you can submit as commands to SQL Server over a Microsoft ActiveX ® Data Objects (ADO) or Hypertext Transfer Protocol (HTTP) connection. The main difference is that templates are used to retrieve data, while Updategrams are used to modify data. Use an Updategram for data modifications that must be:  Performed from a Web site that is based on a SQL Internet Server Application Programming Interface (SQLISAPI). In this case, templates or mapping schemas could be used to retrieve data, and Updategrams could be used to insert, update, or delete data.  Submitted by an organization to a trading partner over the Internet. For example, a supplier could send a delivery request to a shipping company by submitting an Updategram that inserts a record into a Deliveries table. Topic Objective To describe scenarios where you can use Updategrams to modify data. Lead-in You can use Updategrams for data modification in a number of different scenarios. 4 Module 7: XML for SQL Tools Structure of an XML Updategram  Specify the xml-updategram namespace  Mark transactions within the <sync> element  Specify “before” and “after” images of data <root xmlns:updg="urn:schemas-microsoft-com:xml- updategram"> <updg:sync [mapping-schema=mapping schema]> <updg:before> XML Fragment </updg:before> <updg:after> XML Fragment </updg:after> </updg:sync> </root> <root xmlns:updg="urn:schemas-microsoft-com:xml- updategram"> <updg:sync [mapping-schema=mapping schema]> <updg:before> XML Fragment </updg:before> <updg:after> XML Fragment </updg:after> </updg:sync> </root> ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** An Updategram specifies what the XML data looks like now and what it will look like after the Updategram is executed. Specifying the xml-Updategram Namespace Updategrams must reference the Microsoft xml-Updategram namespace (schemas-microsoft-com:xml-Updategram). This namespace defines the elements and attributes that are used in an Updategram. You can reference the xml-Updategram namespace by adding an xmlns attribute declaration in the root element of the Updategram, as shown in the following example. <root xmlns:updg="urn:schemas-microsoft-com:xml-Updategram"> Marking Transactions Within the <sync> Element An Updategram contains one or more <sync> elements. Each <sync> element can contain multiple inserts, updates, or deletes. The failure of one operation in the sync element will cause all other modifications in the same <sync> element to fail. However, in an Updategram that contains multiple <sync> elements, the failure of one <sync> element does not affect the other <sync> elements in the document. Specifying “before” and “after” Images of the Data Represent each data modification by using a <updg:before> and <updg:after> element pair. The <updg:before> element contains an image of the data before the update. The <updg:after> element contains an image of the data after the update. Topic Objective To introduce Updategrams. Lead-in An Updategram is similar to a template, but is used for different purposes. Example Module 7: XML for SQL Tools 5 Mapping Updategram Values to SQL Data  Using Default Mapping  Identical names assumed  Can be attribute-centric, element-centric, or mixed  Specifying a Mapping Schema  Specify a mapping-schema attribute for the <sync> element ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** You can resolve XML elements and attributes in a before or after element of an Updategram to the corresponding SQL Server data in two ways. Using a Default Mapping If no schema is specified, SQL Server will apply a default (or implicit) mapping between the XML data in the Updategram and the data in the database. Consider the following default mapping rules:  Elements that contain attributes or child elements map to table names.  XML attributes and child elements map to database columns that have the same name as the attribute or element. The following Updategram modifies the ProductName column of the Products table: <productupdate xmlns:updg="urn:schemas-microsoft-com:xml-Updategram"> <updg:sync > <updg:before> <Products ProductID="1"> <ProductName>Chai</ProductName> </Products> </updg:before> <updg:after> <Products ProductID="1"> <ProductName>Tea</ProductName> </Products> </updg:after> </updg:sync> </productupdate> Topic Objective To describe how to resolve XML data in an Updategram to SQL Server data. Lead-in You can resolve the XML data in an Updategram by using a default mapping, or by specifying a mapping schema. Example 6 Module 7: XML for SQL Tools Specifying a Mapping Schema Instead of relying on the default mapping, you can explicitly specify a mapping schema that maps XML data to SQL Server data. To specify a mapping schema, add a mapping-schema attribute to the <sync> element in the Updategram. <updg:sync mapping-schema="schema path"> Productschema.xml is a schema file that maps XML data to SQL Server data. <productupdate xmlns:updg="urn:schemas-microsoft-com:xml-Updategram"> <updg:sync mapping-schema="c:\productschema.xml"> <updg:before> <Product ProductCode="1"> <ProductName>Chai</ProductName> </Products> </updg:before> <updg:after> <Product ProductCode="1"> <ProductName>Tea</ProductName> </Products> </updg:after> </updg:sync> </productupdate> Syntax Example [...]... "Provider=SQLOLEDB; Data Source=server1; Database=stock;Integrated Security=SSPI;" SQLxml = "" SQLxml = SQLxml & "" SQLxml = SQLxml & " " SQLxml = SQLxml & " " SQLxml = SQLxml & "" SQLxml = SQLxml & "" SQLxml = SQLxml & "" SQLxml = SQLxml... using the SQLXMLBulkLoad object Example Dim objBL Set objBL=CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad") objBL.ConnectionString ="PROVIDER=sqloledb;" & _ "DATA SOURCE=server1;" & _ "INITIAL CATALOG=retaildb" & _ "INTEGRATED SECURITY=sspi;" objBL.Execute "c:\productschema .xml" , "c:\products .xml" Module 7: XML for SQL Tools 25 SQLXMLBulkLoad and Mapping Schemas Topic Objective To explain how the SQLXMLBulkLoad... J++® Before importing XML data by using the Bulk Load facility, you must define a mapping schema that maps the XML data to columns in the SQL Server database The Bulk Load facility requires an OLE DB connection to SQL Server 24 Module 7: XML for SQL Tools Using the SQLXMLBulkLoad Object Topic Objective To describe the SQLXMLBulkLoad object Lead-in You can script the SQLXMLBulkLoad object to import XML. .. data into SQL Server Creating a SQLXMLBulkLoad Object Set objBL=CreateOhect("SQLXMLBulkLoad.SQLXMLBulkLoad") Set objBL=CreateOhect("SQLXMLBulkLoad.SQLXMLBulkLoad") Loading Data Using the Execute Method Mapping schema and XML source parameters objBL.Execute "c:\productschema .xml" , "c:\products .xml" objBL.Execute "c:\productschema .xml" , "c:\products .xml" *****************************ILLEGAL FOR NON-TRAINER... Note For information about how other annotations are handled by the SQLXMLBulkLoad object, see the XML for SQL documentation Module 7: XML for SQL Tools 27 Bulk Load Options Topic Objective To explain some of the options available when using the SQLXMLBulkLoad object Generate the database schema SGDropTables property Lead-in You can use a number of properties to set options when using the SQLXMLBulkLoad... USE****************************** You can script the SQLXMLBulkLoad object to import XML data into SQL Server This provides a high-performance approach to loading XML data Creating a SQLXMLBulkLoad Object You can instantiate the SQLXMLBulkLoad object in any COM-aware language by using the ProgID “SQLXMLBulkLoad.SQXMLBulkLoad” After you have created the SQLXMLBulkLoad object, it must be connected to a database... updated in the Northwind Traders database 22 Module 7: XML for SQL Tools Inserting XML Data with the Bulk Load Facility Topic Objective To introduce the topics in this section Lead-in You can use the Bulk Load facility to insert large volumes of XML data into SQL Server Bulk Loading XML Data Using the Bulk Load Facility Using the SQLXMLBulkLoad Object SQLXMLBulkLoad and Mapping Schemas Bulk Load Options... "c:\productschema .xml" , "c:\products .xml" Module 7: XML for SQL Tools 31 Lab 7.2: Bulk Loading XML Data Topic Objective To introduce the lab Lead-in In this lab, you will load XML data into SQL Server by using the XML Bulk Load facility *****************************ILLEGAL FOR NON-TRAINER USE****************************** Explain the lab objectives Objectives After completing this lab, you will be able to load XML. .. values: Dim objBL Set objBL=CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad") With objBL ConnectionString ="PROVIDER=sqloledb;" & _ "DATA SOURCE=server1;" & _ "INITIAL CATALOG=retaildb" & _ "INTEGRATED SECURITY=sspi;" SchemaGen=True SGDropTables=True KeepNulls=True KeepIdentity=False End With objBL.Execute "c:\productschema .xml" , "c:\products .xml" Module 7: XML for SQL Tools 29 Handling Bulk Load Errors Topic... before the child element This allows the SQLXMLBulkLoad object to insert the primary key from the parent element into the foreign key column in the table represented by the child element If the child element contains a value for the foreign key field, the value in the child element is inserted into the table Otherwise, the primary key from the parent table is used 26 Module 7: XML for SQL Tools For . com :xml- Updategram' >" SQLxml = SQLxml & "<updg:sync >" SQLxml = SQLxml & " <updg:before>" SQLxml = SQLxml. "<updg:after>" SQLxml = SQLxml & "<Products UnitPrice='$125.99' />" SQLxml = SQLxml & "</updg:after>" SQLxml = SQLxml

Ngày đăng: 10/12/2013, 16:16

Tài liệu cùng người dùng

Tài liệu liên quan