Query and Modification - Advanced Database System - Lecture Slides, Slides of Database Management Systems (DBMS)

Some concept of Advanced Database System are Types Supported, Simple Data Model, Concurrency Control Two, Continuously Adaptive, Cost-Based Optimization, Data Access From Disks, Data Warehousing. Main points of this lecture are: Query and Modification, Data Type, Structure and Storage, Validation, Methods, Schema, Publishing, Queries, Bi-Directional, Query View

Typology: Slides

2012/2013

Uploaded on 04/27/2013

dhanapati
dhanapati 🇮🇳

4.1

(24)

123 documents

1 / 21

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
XML Data in MS SQL Server
Query and Modification
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Partial preview of the text

Download Query and Modification - Advanced Database System - Lecture Slides and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

XML Data in MS SQL Server

Query and Modification

Outline

  • Introduction
  • XML Data Type
    • Structure and storage
    • Schema, validation
    • Methods
  • Publishing
    • FORXML Queries

SQL SERVER 2005 XML Architecture

XML Storage - Native

  • Checks Well Formedness
    • Validation is optional
  • XML Documents or Fragments

XML Storage - The Numbers

  • Advantages of Binary Storage
    • 20 to 30% Size Reduction
    • Faster
  • Limitations
    • 2gb of stored binary per instance
    • Hierarchy is limited to 128 Levels

Storage - Schema

  • Storage Optimization
    • Size
    • Processing
  • Uses the XML Infoset
  • Defined in an XMLSchemaCollection

Validation - Schema Collection

CREATE XML SCHEMA COLLECTION myCollection AS '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://myBooks" elementFormDefault="qualified" targetNamespace="http://myBooks"> <xsd:element name="bookstore" type="bookstoreType" /> <xsd:complexType name="bookstoreType"> <xsd:sequence maxOccurs="unbounded"> <xsd:element name="book" type="bookType" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="authorName"> <xsd:sequence> <xsd:element name="first-name" type="xsd:string" /> <xsd:element name="last-name" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:schema>'

Validation - How?

  • At Data Entry
    • Validness checked when typed data is inserted
  • Checking Data
    • Applied using Cast
  • Updated Schema
    • Does not Require re-validation

query() & nodes() methods

  • Both take XQuery string
  • query() returns list of untyped XML nodes
    • Can be converted to strings
    • For SELECT output
  • nodes() returns list of typed XML nodes
    • All XML DT methods available
    • count(*) works
    • No converting to strings

exist() & value() methods

  • exist()
    • returns true if XQuery returns any nodes
  • value()
    • Takes 2 params: an XQuery & a SQL DT
    • Converts xml value returned by XQuery to specified SQL type

Example: value() w/ nodes()

SELECT book.value(‘(title)[1]’, ‘NVARCHAR(255)’) AS Title FROM Test CROSS APPLY data.nodes(‘/bibliograph/book’) AS R(book)

Title Design Patterns All about XML …

Example: exist()

SELECT book.value(‘(title)[1]’, ‘NVARCHAR(255)’) AS Title FROM Test CROSS APPLY data.nodes(‘/bibliograph/book’) AS R(book) WHERE data.exist(‘/bibliograph/book’) = 1

Title Design Patterns All about XML …

Example: modify()

UPDATE docs SET xCol.modify(‘ insert

Background
after (/doc//section[@num=1])[1]')

Example 2: modify()

UPDATE XmlCatalog SET Document.modify (' declare namespace bk = "http://myBooks"; replace value of (/bk:bookstore/bk:book [@ISBN="1-861003-11- 0"]/bk:price)[1] with 49.99')