Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module 9 Designing an XML Strategy. Module 9: Designing an XML Strategy Designing XML Storage Designing a Data Conversion Strategy Designing an XML Query.

Similar presentations


Presentation on theme: "Module 9 Designing an XML Strategy. Module 9: Designing an XML Strategy Designing XML Storage Designing a Data Conversion Strategy Designing an XML Query."— Presentation transcript:

1 Module 9 Designing an XML Strategy

2 Module 9: Designing an XML Strategy Designing XML Storage Designing a Data Conversion Strategy Designing an XML Query Strategy

3 Lesson 1: Designing XML Storage Overview of Storing Data as XML Scenarios for Storing Data as XML Storing XML and Relational Data Redundantly Selecting a Column Type to Store XML Data Selecting an XML Data Type Index

4 Overview of Storing Data as XML Send data as XML to client applications Support elements Understand the structure of the XML data Use XML schema definition Update XML data Storing Data as XML Split and combine XML data Transfer XML data

5 Guidelines for Storing Data as XML The order of elements is important The data is based on a volatile XML schema The documents require validation You should store data as XML when:   The data contains frequently queried or updated elements The data requires indexes The documents must support concurrent access     You should not store data as XML when:

6 Storing XML Data Redundantly Store non-repeating XML elements in computed columns Add a redundant column to hold frequently queried XML elements Storing Data as XML Store repeating XML elements in a separate table

7 Selecting a Column Type to Store XML Data Supports typed and untyped XML data Support for upto 2 GB of data storage Supports methods such as Query, Modify, and Nodes Supports creation of XML indexes over XML columns Requires additional processing power Supports typed and untyped XML data Support for upto 2 GB of data storage Supports methods such as Query, Modify, and Nodes Supports creation of XML indexes over XML columns Requires additional processing power XML Column Provides good performance NVARCHAR requires 2 GB of storage space to store 1 GB of data VARCHAR can store 2 GB of data Supports property promotion Suitable only for storing and retrieving XML documents Provides good performance NVARCHAR requires 2 GB of storage space to store 1 GB of data VARCHAR can store 2 GB of data Supports property promotion Suitable only for storing and retrieving XML documents VARCHAR NVARCHAR Column VARCHAR NVARCHAR

8 Selecting an XML Data Type Index XML primary index: Creates a structure with tags, values, and paths Required to create XML secondary indexes XML secondary index: Increases the performance of queries Contains three specialized index types–VALUE, PATH and PROPERTY Increases the performance of queries Contains three specialized index types–VALUE, PATH and PROPERTY XML VALUE index: Enhances the performance of content-oriented queries CREATE XML INDEX ON USING XML INDEX FOR VALUE ; GO Enhances the performance of content-oriented queries CREATE XML INDEX ON USING XML INDEX FOR VALUE ; GO XML PATH index: Enhances the performance of structured queries CREATE XML INDEX ON USING XML INDEX FOR PATH ; GO Enhances the performance of structured queries CREATE XML INDEX ON USING XML INDEX FOR PATH ; GO XML PROPERTY index: Enhances the performance of queries that use the Name or Value predicates CREATE XML INDEX ON USING XML INDEX FOR PROPERTY ; GO Enhances the performance of queries that use the Name or Value predicates CREATE XML INDEX ON USING XML INDEX FOR PROPERTY ; GO

9 Lesson 2: Designing a Data Conversion Strategy Creating a Data Conversion Strategy Converting Relational Data into XML Data Demonstration: How To Convert Relational Data into XML Data Converting XML Data to a Rowset Demonstration: How To Convert XML Data into Relational Data

10 Creating a Data Conversion Strategy Evaluate the application requirements for the data format 1 1 Determine whether to convert data on the server side or client side 4 4 Determine the most efficient database storage method 2 2 Determine data access and modification methods 3 3

11 Converting Relational Data into XML Data FOR XML clause is used to convert relational data to XML data

12 Demonstration: How To Convert Relational Data into XML Data In this demonstration, you will see how to: Convert relational data into XML data

13 Notes Page Over-flow Slide. Do Not Print Slide. See Notes pane.

14 Converting XML Data to a Rowset Use the OPENXML option to convert XML data Use a user-defined function to encapsulate conversion logic Use XML nodes method to convert XML data

15 Demonstration: How To Convert XML Data into Relational Data In this demonstration, you will see how to: Convert XML data into relational data with query function

16 Writing Queries by Using XQuery Using XQuery to Modify XML Data Parameterizing XQueries Using XPath Expressions Using XQuery in the WHERE Clause of a DML Statement Lesson 3: Designing an XML Query Strategy

17 XQuery ExpressionsXQuery OperatorsXML Constructors Primary Sequence Conditional Quantified Sequence type FLWOR Logical Comparison Arithmetic Direct Computed Writing Queries by Using XQuery 123…

18 Notes Page Over-flow Slide. Do Not Print Slide. See Notes pane.

19 Using XQuery to Modify XML Data You can modify XML documents by using the modify method of the XML data type and specify the modification by using XML DML statements. OperationDescription Insert You can use the insert keyword to insert one or more nodes in an XML document. The insert keyword accepts an XQuery expression that identifies the nodes to be inserted and another XQuery expression that specifies the reference node. Delete The delete keyword enables you to delete one or more nodes from an XML instance. The delete keyword accepts an XQuery expression that identifies one or more nodes to be deleted from the XML document. Update The replace value of keyword enables you to modify the value of an existing node. To modify the value of an existing node, you have to specify an XQuery expression that identifies the node whose value is to be updated and another expression that specifies the new value of the node.

20 sql:column: Use the sql:column function to retrieve and combine XML and non-XML values into single XML structures Sql:variable: Use the sql:variable function to retrieve variable values T-SQL Variable Parameterizing XQueries XML Column Non-XML Column Single XML Structure Variable Value Parameterized XQuery allow developers to pass information from TSQL to XQuery and vice versa with help of parameter

21 Administrator Using XPath Expressions User-Defined Function Create a user-defined function that contains the path expressions necessary to access XML data Constraint to a Table Create a function that contains the necessary logic, and then use that function in your constraint definition XML Indexes Create any of the following to retrieve data: Primary index Value index Path index Property index Create any of the following to retrieve data: Primary index Value index Path index Property index An Xpathexpression uses a path notation, like those used in URLs, for addressing parts of an XML document

22 Using XQuery in the WHERE Clause of a DML Statement

23 Lab 9: Designing an XML Strategy Exercise 1: Designing an XML Data Storage Model Exercise 2: Converting Data Between XML and Relational Forms Estimated time: 60 minutes Logon Information Virtual machine User name Password NYC-SQL1 Administrator Pa$$w0rd

24 Lab Scenario You are a lead database designer at QuantamCorp. You are working on the Human Resources Vacation and Sick Leave Enhancement (HR VASE) project that is designed to enhance the current HR system of your organization. This system is based on the QuantamCorp sample database in SQL Server 2008. The main goals of the HR VASE project are as follows:  Provide managers with current and historical information about employee vacation and sick leave.  Grant view rights to individual employees to view their vacation and sick leave balances.  Provide permission to selected employees in the HR department to view and update the vacation and sick leave details of employees.  Grant the HR manager with the view and update rights to all the data. QuantamCorp currently has a LocalAccounts database at each regional office. This database contains all customer account information in a nonsummarized format. The HR VASE application uses the Accounts database to calculate the staff’s performance metric. A user makes a new request to enhance the local account application to store information about customers’ requests for enquiry and service. The development team has decided to use the XML format to transfer data. The team has taken up this task to reduce the complexity of transferring additional data between the LocalAccounts database. The organization wants you to review the current solution and propose an updated database model that supports these requirements.

25 Lab Review In this lab, you: Designed XML storage Converted XML data into relational data

26 Module Review and Takeaways Review Questions Real-world Issues and Scenarios Tools


Download ppt "Module 9 Designing an XML Strategy. Module 9: Designing an XML Strategy Designing XML Storage Designing a Data Conversion Strategy Designing an XML Query."

Similar presentations


Ads by Google