The XML data type in Microsoft SQL Server. The XML Type Microsoft SQL Server offers a special data type – XML – Used in tables, etc. – Basically a (long)

Slides:



Advertisements
Similar presentations
DB glossary (focus on typical SQL RDBMS, not XQuery or SPARQL)
Advertisements

Advanced SQL (part 1) CS263 Lecture 7.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Stored procedures Procedural programming in Microsoft SQL Server 1Stored procedures.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts - 6 th Edition SQL Schema Changes and table updates instructor teaches.
Module 9 Designing an XML Strategy. Module 9: Designing an XML Strategy Designing XML Storage Designing a Data Conversion Strategy Designing an XML Query.
Viewing relational data as XML Using Microsoft SQL Server.
4/20/2017.
2.2 SQL Server 2005 的 XML 支援功能. Overview XML Enhancements in SQL Server 2005 The xml Data Type Using XQuery.
Object and object-relational databases 1. Object databases vs. Object-relational databases Object databases Stores complex objects – Data + functions.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
Using XML in SQL Server 2005 NameTitleCompany. XML Overview Business Opportunity The majority of all data transmitted electronically between organizations.
Chapter 10 Queries and Updating Part C. SQL Copyright 2005 Radian Publishing Co.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
XML in SQL Server Overview XML is a key part of any modern data environment It can be used to transmit data in a platform, application neutral form.
Introduction to Databases Chapter 7: Data Access and Manipulation.
Triggers Event handlers in the DBMS. Triggers are event handlers Triggers a executed when an event happens in the DBMS Example events – INSERT, UPDATE.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Introduction to SQL Steve Perry
Sofia, Bulgaria | 9-10 October Using XQuery to Query and Manipulate XML Data Stephen Forte CTO, Corzen Inc Microsoft Regional Director NY/NJ (USA) Stephen.
DBSQL 14-1 Copyright © Genetic Computer School 2009 Chapter 14 Microsoft SQL Server.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
SQL advanced select using Oracle 1 7. Multiple Tables: Joins and Set Operations 8. Subqueries: Nested Queries.
SQL Server 7.0 Maintaining Referential Integrity.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
5/24/01 Leveraging SQL Server 2000 in ColdFusion Applications December 9, 2003 Chris Lomvardias SRA International
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Exam and Lecture Overview.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
CS 1308 Computer Literacy and the Internet
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
JSTL The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
Session 11 Creating Tables and Using Data Types. RDBMS and Data Management/Session 11/2 of 40 Session Objectives Define the data types and list the categories.
DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.
Visual Programing SQL Overview Section 1.
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
SQL Server 2012 Session: 1 Session: 8 Accessing Data Data Management Using Microsoft SQL Server.
SQL advanced select using Oracle 1. 2 Select Simple –data from a single table Advanced –data from more tables join sub-queries.
CpSc 462/662: Database Management Systems (DBMS) (TEXNH Approach) Relational Schema and SQL Queries James Wang.
Database Basics BCIS 3680 Enterprise Programming.
Assertions and triggers1. 2 Constraints Attribute-based CHECK constraints create table … ( postcode number(4) check (postcode > 0) ); Checked at update.
SQL Server 2005: Extending the Type System with XML.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
SQL Statements: Queries. Relational Databases Relational Databases organize the data in tables with rows and columns. This is similar to the organization.
Module 3: Using XML. Overview Retrieving XML by Using FOR XML Shredding XML by Using OPENXML Introducing XQuery Using the xml Data Type.
Ch 5. Introducing More Database Objects. Database Objects Table (ch2) View (ch3) Stored Procedure Trigger Function User-defined types.
Jennifer Widom Relational Databases The Relational Model.
LINQ Language Integrated Query LINQ1. LINQ: Why and what? Problem Many data sources: Relational databases, XML, in-memory data structures, objects, etc.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 18 A First Course in Database Systems.
 MySQL  DDL ◦ Create ◦ Alter  DML ◦ Insert ◦ Select ◦ Update ◦ Delete  DDL(again) ◦ Drop ◦ Truncate.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
SQL Server getting closer to
XML: Extensible Markup Language
Dirt, Spit, and Happy FLWOR
Overview Implementing Triggers Implementing XML Schemas.
Relational Databases The Relational Model.
Relational Databases The Relational Model.
Contents Preface I Introduction Lesson Objectives I-2
CPSC-608 Database Systems
IST 318 Database Administration
Presentation transcript:

The XML data type in Microsoft SQL Server

The XML Type Microsoft SQL Server offers a special data type – XML – Used in tables, etc. – Basically a (long) text string With some special features Example, create table Create table course ( courseID int identity(1,1) primary key, coursename varchar(50) not null, description xml) An attribute with the XML type can be NULL or NOT NULL Example, insert insert into course (coursename, description) values ('Accounting', ' Accounting blah blah '); 2The XML data type

Typed vs. non-typed XML Typed XML – The XML data type has an associated XML schema – The DBMS verifies that the XML input validates using the schema at INSERT and UPDATE Non-typed XML – The XML data type does not have an associated XML schema – The DBMS verifies that the XML input is well formed at INSERT AND UPDATE 3The XML data type

Creating an XML schema collection create xml schema collection departmentDescriptionCollection as ' ' 4The XML data type

Using an XML schema collection Example, CREATE – CREATE TABLE department( – departmentID int IDENTITY(1,1) NOT NULL, – departmentName varchar(50) NOT NULL, – description xml(CONTENT departmentDescriptionCollection) Example, INSERT insert into department (departmentName, description) values ('accounting', ' Accounting blah blah '); 5The XML data type

XML Data type methods The XML data type has 5 methods –.query(…) Using XQuery –.value(…) Access values inside a specific element or attribute –.modify(…) Modify the XML data Not part of the XQuery standard –.nodes(…) Break XML data into relational-style rows –.exists(…) Tests whether a specific kind of data exists The XML data type6

XQuery Quotes – XQuery is to XML, what SQL is to database tables. – XQuery was designed to query XML data. – From The XML data type7

Simple XQuery expressions Executed on a variable, not a table column xml; = N' 250 GB hard drive 120 USB Mouse 25 ' select Source: Lee & Bieker: Mastering Microsoft SQL Server 2008, Sybex /Wiley 2009, page The XML data type

Simple XQuery Executed on a database column Example, SELECT with XQuery select name, description.query('/root/shortDescription') from course; The XML data type9

XML.value(…) method.query() vs.value() – select departmentName, description.query('/root/shortDescription') from department; Returns departmentName + XML fragment – select departmentName, description.value('/root/shortDescription', 'varchar(50)') from department; Returns departmentName + description – Description is converted into a varchar(50).value(XQuery, SQLtype) – The Xquery must return at most one value. Syntax often used (…)[1] – Only the fist element is considered. The XML data type10

XML.modify(…) method XQuery can only select data – Not modify data Microsoft has extended XQuery to include modification – insert – delete – replace value of Example, UPDATE … replace value of … UPDATE department SET description.modify('replace value of (/root/shortDescription) with "another description"') WHERE departmentid = 9 The XML data type11

XML.nodes(…) method Breaking XML data into their own table – This temporary table is often ”joined” with the table that has the XML column. Syntax – SELECT columns FROM table CROSS APPLY columnName.nodes(XQuery) AS alias – ”CROSS APPLY” is a kind of join The XML data type12

XML.exist() method Similar to the EXISTS operator in ordinary SQL. XML.exist(XQuery) – Returns 1 (true) or 0 (false)! Used in SELECT … WHERE … Example SELECT departmentName FROM department WHERE description.exist('/root/shortDescription') = 1; The XML data type13