230 likes | 373 Views
Module 9 Designing an XML Strategy. Module 9: Designing an XML Strategy. Designing XML Storage Designing a Data Conversion Strategy Designing an XML Query Strategy. Lesson 1: Designing XML Storage. Overview of Storing Data as XML Scenarios for Storing Data as XML
E N D
Module 9 Designing an XML Strategy
Module 9: Designing an XML Strategy Designing XML Storage Designing a Data Conversion Strategy Designing an XML Query Strategy
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
Overview of Storing Data as XML <any> < xml > Send data as XML to client applications < xml > Split and combine XML data Support <any> elements Use XML schema definition Update XML data Understand the structure of the XML data Transfer XML data < xml > < xml > < xml > < xml > < xml > < xml > < xml > < xml > Storing Data as XML
Guidelines for Storing Data as XML You should not store data as XML when: You should store data as XML when: The order of elements is important ü The data contains frequently queried or updated elements × The data requires indexes × The data is based on a volatile XML schema ü The documents must support concurrent access × The documents require validation ü < xml >
Storing XML Data Redundantly < ? xml ?> < ? xml ?> Storing Data as XML < xml >
Selecting a Column Type to Store XML Data < xml > XML Column VARCHAR NVARCHAR Column • 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 • 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
Selecting an XML Data Type Index XML primary index: XML VALUE index: • Creates a structure with tags, values, and paths • Required to create XML secondary indexes Enhances the performance of content-oriented queries CREATE XML INDEX <index name> ON <column> USING XML INDEX <primary XML index name> FOR VALUE ; GO XML secondary index: • Increases the performance of queries • Contains three specialized index types–VALUE, PATH and PROPERTY XML PATH index: Enhances the performance of structured queries CREATE XML INDEX <index name> ON <column> USING XML INDEX <primary XML index name> FOR PATH ; GO XML PROPERTY index: Enhances the performance of queries that use the Name or Value predicates CREATE XML INDEX <index name> ON <column> USING XML INDEX <primary XML index name> FOR PROPERTY ; GO
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
Creating a Data Conversion Strategy 1 Evaluate the application requirements for the data format < xml > < xml > < xml > < xml > 2 Determine the most efficient database storage method 3 Determine data access and modification methods 4 Determine whether to convert data on the server side or client side
Converting Relational Data into XML Data < xml > Mode Use RAW Generates one XML element per row AUTO Nests the elements based on the relational schema EXPLICIT Shapes the XML data PATH Combines elements and attributes FOR XML clause is used to convert relational data to XML data
Demonstration: How To Convert Relational Data into XML Data In this demonstration, you will see how to: Convert relational data into XML data
Converting XML Data to a Rowset < xml > Use the OPENXML option to convert XML data Use XML nodes method to convert XML data Use a user-defined function to encapsulate conversion logic
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
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
Writing Queries by Using XQuery < xml > < xml > < xml > XQuery Expressions XQuery Operators XML Constructors 123… • Primary • Sequence • Conditional • Quantified • Sequence type • FLWOR • Logical • Comparison • Arithmetic • Direct • Computed
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.
Parameterizing XQueries XML Column Non-XML Column Single XML Structure Variable Value T-SQL Variable Parameterized XQuery allow developers to pass information from TSQL to XQuery and vice versa with help of parameter 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
Using XPath Expressions An Xpathexpression uses a path notation, like those used in URLs, for addressing parts of an XML document User-Defined Function Constraint to a Table Create a user-defined function that contains the path expressions necessary to access XML data 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 Administrator
Using XQuery in the WHERE Clause of a DML Statement Use the exist method when possible Create a path index on the XML column Do not create an XML computed column if you must index that column
Lab 9: Designing an XML Strategy Exercise 1: Designing an XML Data Storage Model Exercise 2: Converting Data Between XML and Relational Forms Virtual machine NYC-SQL1 Administrator User name Password Pa$$w0rd Logon Information Estimated time: 60 minutes
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.
Lab Review In this lab, you: Designed XML storage Converted XML data into relational data