Tải bản đầy đủ (.pdf) (30 trang)

Tài liệu Module 9: SQL XML pptx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (913.8 KB, 30 trang )









Contents
Overview 1
Lesson: XML Support in SQL Server 2000 2
Lesson: Using HTTP to Access and Input
XML Data 10
Lab 9: Creating SQL Queries Using XML 17
Review 22

Module 9: SQL XML



Information in this document, including URL and other Internet Web site references, is subject to
change without notice. Unless otherwise noted, the example companies, organizations, products,
domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious,
and no association with any real company, organization, product, domain name, e-mail address,
logo, person, places or events is intended or should be inferred. Complying with all applicable
copyright laws is the responsibility of the user. Without limiting the rights under copyright, no
part of this document may be reproduced, stored in or introduced into a retrieval system, or
transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or
otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

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, MS-DOS, Windows, Windows NT, ActiveX, BackOffice, bCentral, BizTalk,
FrontPage, MSDN, MSN, Netshow, PowerPoint, SharePoint, Visio, Visual Basic, Visual C++,
Visual C#, Visual InterDev, Visual Studio, Windows Media, and Xbox are either registered
trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries.

The names of actual companies and products mentioned herein may be the trademarks of their
respective owners.


Module 9: SQL XML iii


Instructor Notes
This module provides participants with an introduction to the use of Extensible
Markup Language (XML) with Microsoft
®
SQL Server

2000.
SQL Server 2000 is one of the Microsoft .NET Enterprise Servers. As such, it
is an example of how all the .NET Enterprise Servers are changing to fully
support XML technologies.
This chapter will give participants an understanding of the diversity of XML
support in SQL Server without overwhelming them. This is a complex topic

and might not be easily understood by all participants at first.
Make certain that participants know that this module covers a major topic and
that there is an entire course devoted to it. That course is Course 2091A,
Building XML-Enabled Applications Using Microsoft SQL Server 2000.
After completing this module, participants will be able to:
!
Describe how SQL Server 2000 uses XML.
!
Describe how to implement XML support in SQL Server 2000.
!
Write basic XML queries against SQL Server 2000 by using Hypertext
Transfer Protocol (HTTP).
!
Use a basic XML template against SQL Server 2000 to retrieve data.
!
Insert data into SQL Server 2000 by using XML.
!
Describe some of the XML features recently added to SQL Server 2000.

Presentation:
30 Minutes

Lab:
45 Minutes
iv Module 9: SQL XML


Materials and Preparation
This section provides the materials and preparation tasks that you need to teach
this module.

To teach this module, you need the following materials:
• Microsoft PowerPoint
®
file 2500A_09.ppt

To prepare for this module:
!
Read all of the materials indicated for this module and complete all labs
and practices.
!
Read the topic “XML and Internet Support” in SQL Server 2000
Books Online.
!
Familiarize yourself with Course 2091A, Building XML-Enabled
Applications Using Microsoft SQL Server 2000. Note the differences
between the XML support described in the course and the XML support in
the XML for SQL Server 2000 add-in.

Instructor Setup for a Lab
This section provides setup instructions that are required to prepare the
instructor computer or classroom configuration for a lab.
!
Prepare for the lab
1. Be sure that Internet Information Services (IIS) is properly configured
and working.
2. Be sure that Configure SQL XML Support in IIS is available in the
Microsoft SQL Server program group menu.
3. Work through as many examples as you can in addition to the lab exercises,
because the participants may ask questions about what else can be done with
XML and SQL queries.



According to the Manual Setup Guide, the SQL password is set to 2500.

Required materials
Preparation
tasks
Lab 9: Creating SQL
Queries Usin
g XML
Note
Module 9: SQL XML v


Demonstration
This section provides demonstration procedures that will not fit in the margin
notes or are not appropriate for the student notes.
!
Prepare for the demonstration
1. Be sure that you have read and practiced the steps required to successfully
install XML support for IIS.
2. Be sure that you are familiar with the various properties pages for
configuring a virtual directory.
3. Test the setup and configuration, and make sure that it will properly process
a Uniform Resource Locator (URL) query and return the results to the
browser properly.
4. If you discover any problems with the configuration, be sure to fix them
before you give the demonstration, because it can be time consuming to
resolve them.


!
Set up the virtual directory in IIS to publish a SQL Server database
1. Click Start, point to All Programs, point to Microsoft SQL Server, and
then click Configure SQL XML Support in IIS.
2. Expand your server, right-click Default Web Site, point to New, and then
click Virtual Directory.
3. In the New Virtual Directory Properties dialog box, on the General tab,
make Nwind09 the value for the Virtual Directory Name setting.
4. Click Browse, browse to \Inetpub\wwwroot\ to select the local path, and
then click Make New Folder.
5. Type NwindSite and then click OK.
6. On the Security tab, select Use Windows Integrated Authentication.
7. On the Data Source tab, use the following settings and values.
Setting Value

SQL Server (local)
Database Northwind

8. On the Settings tab, select all the check boxes so that all query types are
allowed.

Setting up XML in SQL
Server 2000
vi Module 9: SQL XML


!
Set up the schema and template virtual names on IIS
1. Open Microsoft Windows
®

Explorer, and then navigate to the
\Inetpub\wwwroot\NwindSite folder.
2. Create a new folder named templates and another new folder named
schemas.
3. In the New Virtual Directory Properties dialog box, on the Virtual
Names tab, click New to create the virtual name for the template.
4. In the Virtual Name Configuration dialog box, in the Virtual name box,
type template09
5. In the Type list, click template.
6. Click the ellipsis button (…), browse to the
\Inetpub\wwroot\NwindSite\templates folder, and then click OK.
7. In the Virtual Name Configuration dialog box, click Save.
8. Repeat steps 3 through 7. Use schema09 for the virtual name, schema for
the type, and browse to the schemas folder.
9. Close the New Virtual Directory Properties dialog box.
10. Close the IIS Virtual Directory Management for SQL Server console.

!
Prepare for the demonstration
1. Read the documentation on the XML View Mapper and familiarize yourself
with its architecture, purpose, and functionality.
2. Practice the tutorial carefully more than once.
3. To present this demonstration, use the tutorial to show how the XML View
Mapper works. The steps are not reproduced here. You might want to print
out the tutorial section of the XML View Mapper documentation.

The XML View Mapper
Module 9: SQL XML vii



Module Strategy
This module represents a wide range of topics. In many ways, it does not cover
them sufficiently. That is why there is a full course on this topic, which is now
partially out of date due to the XML for SQL Server 2000 add-in. Stress that
this is strictly an overview of the topic, which is consistent with the overall
nature of this course as an introduction. Use the following strategy to present
this module:
!
XML Support in SQL Server 2000
This lesson gives the reasons for having XML support in SQL Server 2000
and the major capabilities of XML support in SQL Server 2000.
!
Using HTTP to Access and Input XML Data
This lesson describes the power of using XML and SQL in queries through
Hypertext Transfer Protocol (HTTP) access to SQL Server. Be ready to
explain why this capability is interesting and useful.
Discuss the security risk of allowing direct URL queries. One risk is that
URL queries expose database structure. Another risk is that identity of the
issuer of the request may not be known. For these reasons, limit the use of
URL queries.
Contrast allowing direct URL queries with using XML Path Language
(XPath) and XML Schema Definitions (XSD) schemas. This approach has
an important security advantage over allowing URL queries. Template files
enhance security by hiding details of the database schema from the end user.

The following lessons are included in Appendix C.
!
FOR XML and OpenXML
In this lesson, you see two methods of querying SQL Server 2000 by using
tools available through the XML for SQL Server 2000 add-in.

!
Manipulating XML Using Transact-SQL
This lesson shows participants how Transact-SQL and XML are useful and
powerful when used together. This can take up a lot of the module time, so
move through it briskly.
!
Retrieving XML Data with ADO and ADO.NET
This lesson is a quick overview. The topic is too large for this course, and
there is not time to cover the topic in more depth. If you have time and are
able to, elaborate on the evolution from ADO to ADO.NET. Be prepared for
questions, and be ready to provide examples. Remind participants that there
is an ADO.NET course.
!
Using Mapping Schemas
Explain why mapping is useful and how it fits in with other products and
technologies, particularly Microsoft BizTalk

Server 2000. Emphasize the
importance of graphical tools like BizTalk Server. Also, emphasize that
tools like BizTalk Server are new and will become more sophisticated and
friendly for the developer and user.
Appendix
viii Module 9: SQL XML


!
Updategrams and Bulk Load
Updategrams and the Bulk Load utility are relatively straightforward, but be
sure to explain why they are needed. Because this topic can be slightly
confusing, be prepared to give additional examples or to elaborate on the

ones provided. Read the background materials on these topics.
!
Ideas and Future of XML and SQL
The purpose of this topic is to emphasize that SQL XML is developing
rapidly. The map example shows a different way to use XML and
SQL Server together.
Stress that Microsoft is enhancing XML support in SQL Server. The speed
of the evolution of the Internet and the development of .NET caused
Microsoft to release the XML for SQL Server 2000 add-in, rather than wait
for an entire product cycle. Check the SQL Server site and the Microsoft
MSDN
®
SQL Server site before each class to see if any new XML and SQL
enhancements or product add-ins are announced.

Module 9: SQL XML 1


Overview
!
XML Support in SQL Server 2000
!
Using HTTP to Access and Input XML Data

*****************************
ILLEGAL FOR NON
-
TRAINER USE
******************************
Microsoft

®
SQL Server

2000 plays a crucial role in the Microsoft .NET
strategy as a means of enabling the easy use of data with Extensible Markup
Language (XML) technologies.
This module presents a detailed overview of the implementation of XML in
SQL Server 2000 and add-ins to the product since its release in 2000. Key
points are covered here for your understanding. In-depth coverage of these
topics is available in related SQL Server and Microsoft Visual Studio
®
courses.
After completing this module, you will be able to:
!
Describe how SQL Server 2000 uses XML.
!
Describe how to implement XML support in SQL Server 2000.
!
Write basic XML queries against SQL Server 2000 by using Hypertext
Transfer Protocol (HTTP).
!
Use a basic XML template against SQL Server 2000 to retrieve data.
!
Insert data into SQL Server 2000 by using XML.
!
Describe some of the XML features recently added to SQL Server 2000.


For in-depth coverage of the implementation of XML in
SQL Server 2000, see Course 2091A, Building XML-Enabled Applications

Using Microsoft SQL Server 2000.
In this module, you will use SQL Query Analyzer to connect to the Northwind
database. To do this, you need the SQL password. According to the Manual
Setup Guide, the SQL password is set to 2500.

Introduction
Objectives
Im
portant
2 Module 9: SQL XML


Lesson: XML Support in SQL Server 2000
!
XML Features in SQL Server 2000
!
SQL Server XML Architecture
!
XML for SQL Server 2000

*****************************
ILLEGAL FOR NON
-
TRAINER USE
******************************
While developing SQL Server 2000, Microsoft determined that the use of XML
for Internet-based work was a major requirement. This lesson describes the
XML support incorporated in the product. Just as XML technologies are
changing rapidly, so too are the XML technologies in SQL Server.
The normal development cycle of three to four years is too long, so interim

releases of new XML support in SQL Server are being provided through add-in
features. You will learn about some of these in this lesson.
After completing this lesson, you will be able to:
!
Describe key XML features supported in SQL Server 2000.
!
Describe the architectural features providing XML support in
SQL Server 2000.
!
Identify and describe features added to SQL Server 2000 for XML support.
!
Explain the range of ways in which SQL Server 2000 provides support for
XML in general and for Microsoft .NET in particular.

Introduction
Lesson objectives
Module 9: SQL XML 3


XML Features in SQL Server 2000
!
HTTP access to SQL Server
!
XML Views
!
XSD and XPath support for queries
!
Retrieve and write XML data
"
FOR XML clause

"
OPENXML rowset provider
!
Stream support through enhancements to SQLOLEDB
!
XML for SQL Server 2000

*****************************
ILLEGAL FOR NON
-
TRAINER USE
******************************
One of the major benefits of combining SQL Server relational data and XML
data is that it enables you to easily translate hierarchical data into relational data
and vice versa. To achieve this, SQL Server relies on several technologies.
Some are provided with the XML for SQL Server 2000 add-in, and others are
the result of SQL Server interoperating with other .NET Enterprise Server
products.
SQL Server interoperates with Internet Information Services (IIS) to process
queries by using HTTP. Such queries are encoded in Uniform Resource Locator
(URL) strings.
This table presents some examples of HTTP queries.
HTTP query type Example
Direct query to
SQL Server
http://bandicoot/nwind?sql=SELECT+*+FROM
+Employees+FOR+XML+AUTO&root=root
Query that references an
XML schema
http://bandicoot/nwind?template=

<ROOT+xmlns:sql="urn:schemas-microsoft-com:xml-
sql"><sql:query>SELECT+*+FROM+Employees+FOR
+XML+AUTO</sql:query></ROOT>
Query that references a
template file
http://bandicoot/nwind/MyTemplates/mytemplate.xml
Query that references an
XSD schema and includes
XPath
http://bandicoot/nwind/MySchemas/myschema.xml
/Employee[@EmployeeID="2"]
Query that references a
database object directly
http://bandicoot/nwind/MyObjects/XpathQuery

Introduction
HTTP access
Examples
4 Module 9: SQL XML


An XML View allows a query to be processed by using an XML-Data Reduced
(XDR) schema. An XML View can be queried by using XML Path Language
(XPath). This is analogous to using the CREATE VIEW statement in SQL.
By using XPath and XSD schemas, which enable you to map database
information, you can directly query the database. This approach has an
important security advantage over allowing URL queries. Template files
enhance security by hiding details of the database schema from the end user.
Normally, SQL queries return data in rowset format. An SQL query that uses
the FOR XML clause returns data in XML format. You can further qualify the

FOR XML clause by using the RAW, AUTO, or EXPLICIT modes.
You can also insert data into the database directly from XML by using the
special stored procedure sp_xml_preparedocument and the OPENXML
rowset provider.
To provide the enhanced capabilities for XML support, the Microsoft OLE DB
Provider for SQL Server (SQLOLEDB) has new properties that enable you to
handle streams with XML data.
XML Views
XSD and XPath querying
Read/write XML data
Enhanced SQLOLEDB

×