Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQL/XML Was sagt die Norm?. History SQL-86  the first version of the Structured Query Language Standard: -ANSI 1986 -ISO 1987  provides: -the notion.

Similar presentations


Presentation on theme: "SQL/XML Was sagt die Norm?. History SQL-86  the first version of the Structured Query Language Standard: -ANSI 1986 -ISO 1987  provides: -the notion."— Presentation transcript:

1 SQL/XML Was sagt die Norm?

2 History SQL-86  the first version of the Structured Query Language Standard: -ANSI 1986 -ISO 1987  provides: -the notion of named tables, rows, columns -DDL constructs to create tables -DML constructs to insert, update and delete rows from tables -query expressions to retrieve selected rows -set of built-in types -privileges to control access to tables -facilities to specify declarative integrity constraints SQL-89  enhances SQL-86 with the notion of referential integrity

3 SQL-92  enhancements: -additional data types -outer joins -catalogues -domains -assertions -temporary tables -referential actions -schema manipulation language -dynamic SQL -information schema tables -greater orthogonality  incremental parts  1995 - SQL/CLI : functions as a callable interface to an SQL database system, providing a highly dynamic capability  1996 – SQL/PSM : -stored procedures : ability to execute block-structured compound statements, flow-of-control statements, local variables, condition handlers -SQL-invoked routines : functions – allowed to be overloaded, procedures

4 SQL:1999  a 5-part standard consisting of: 1.SQL/Framework 2.SQL/Foundation 3.SQL/CLI (Call Level Interface) 4.SQL/PSM (Persistent Stored Modules) 5.SQL/Bindings  enhancements: -object-relational facilities -additional predefined data types: BOOLEAN, CLOB, BLOB -type constructors: ROW, REF, ARRAY -the ability to create user-defined distinct and structured data types -3 new predicates: SIMILAR, DISTINCT, type predicate -ability to formulate recursive queries -the notion of savepoints, roles -triggers  incremental parts  9. SQL/MED (Management of External Data): extensions to the SQL language to query and manipulate external data, to join it with local SQL-data  10. SQL/OLB (Object Language Bindings)  13. SQL/JRT (Routines and Types Using the Java Programming Language): in combination with SQL/OLB, establishes a tight union between the Java application programming language and SQL  Addendum : complex statistical and data analysis functions executed as part of ordinary SQL-statements

5 SQL:2003  new functionality: -the MERGE statement -identity, respectively generated columns -sequence generators -OLAP -CREATE TABLE … AS query -tablesample -multiple assignment -MULTISET types -the BIGINT type -improved savepoint handling -enhanced diagnostics  new part: 14. SQL/XML (XML-Related Specifications)

6 Introduction Motivation  only XML-data => XML-query language (XQuery)  only object-relational data => usual SQL  integrated use of XML- and traditional SQL-data, accessed through SQL => SQL/XML SQL/XML  allows applications to store XML-documents within SQL-databases -new data type : XML to produce XML-documents from traditional SQL-data -mapping from SQL-tables to XML-documents -to generate XML from SQL-data  under discussion to produce SQL-data from XML-documents to update XML-documents to search for texts in XML-documents  operations parse operation: XML(string) -> SQL(XML_value) serialize operation: SQL(XML_value) -> XML(string)

7 The XML Data Type Values: NULL XML-document individual XML-elements sequences of XML-elements Use: to define columns variables parameters Comparability:  XML-values are not comparable  the user must explicitly define order, if XML-values are to be compared

8 Examples (XML-values): 4000 4000 Dieter Grau 4000 Dieter Grau 4000 Black Kim Black Example (use of XML data type): CREATE TABLE Employees( ID Integer, Salary Decimal(12,2), JobApplication XML );

9 IDSalaryJobApplication 5011487000 Gisela Blum Alexanderstrasse 39 Datenbanken SQL Oracle Postgres DB2 2204434000 Dieter Grau Editharing 31 Datenbanken Informix DB2

10 XML-Functions XMLELEMENT  produces an XML-element  syntax: XMLELEMENT (Name [, XMLATTRIBUTES( )] [, ] ) := [AS ] where the ValueExpressionList defines the content of the XML-element. XMLATTRIBUTES  used to create XML-attributes  example: SELECT e.id ID, XMLELEMENT(Name “Emp”, XMLATTRIBUTES(e.id), e.lname ) AS Employee FROM employees e; IDEmployee 1001 Smith 1206 Martin

11 XMLAGG  produces a single XML-value from a group of XML-values  syntax: XMLAGG( [ORDER BY ])  example: SELECT XMLELEMENT(Name “Dept”, XMLATTRIBUTES(e.dept AS name”), XMLAGG(XMLELEMENT(NAME “emp”, e.lname) ORDER BY e.lname) ) AS Dept_List FROM employees e; Dept_List Smith Yates Martin Dylan

12 XMLCONCAT  concatenates two or more XML-values  syntax: XMLCONCAT( )  example: SELECT XMLCONCAT( XMLELEMENT(NAME “Name”, Name), XMLELEMENT(NAME “Euro”, 12*Salary) ) AS Emp_Salary FROM employees; Emp_Salary Smith 24000 Moore 32000

13 XMLFOREST  creates a sequence of XML-elements  syntax: XMLFOREST( ) >:= [AS ]  example: SELECT XMLFOREST(ID, XMLELEMENT(NAME “Euro”, 12*Salary) AS Salary) AS Emp_Salary FROM employees; Emp_Salary 501148 36000 220443 48000 170470 84000 160139 48000

14 Mapping between SQL and XML The SQL/XML Norm specifies mapping between the following concepts:  SQL-value → XML-value  SQL-character set ↔ XML-Unicode  SQL-identifier ↔ XML-name  SQL-data type ↔ XML-schema name  SQL-table ↔ XML-document + XML-schema document  SQL-schemes ↔ XML-document + XML-schema document  SQL-catalog ↔ XML-document + XML-schema document SQL/XML makes available an XML-Namespace that serves as a base for mapping between SQL and XML. This defines in XML  the SQL-data type forms (predefined data type, domain, row type, array type, multiset type and distinct type)  the predefined SQL-data types  the SQL-schema objects (catalogue, schema, base table, view, character set, collation)

15 Mapping from SQL-Values to XML-Values set by mapping of corresponding data types exceptions:  numerical data types : decimal point missing when no values after following it  strings : special symbols mapped to their counterpart in XML examples: SQL-data typeSQL-valueXML-value NUMERIC(12,2)1003.44 NUMERIC(12,2)1003.01003 CHAR(20)‘SQL:2003’SQL:2003 VARCHAR(20)‘ ’<SQL:2003>

16 Mapping from SQL-Identifiers to XML-Names Regular identifiers:  1:1 mapping  capital letters, as internally SQL-identifiers are displayed in upper case letters  example: Employee → Identifiers containing special symbols:  special symbols are not allowed in qualified XML-names  mapping: _x UnicodeValue _  mapping is reversible  examples: “SQL:2003*” → SQL_x003A_2003_x003E_ “©Türker” → _x00A9_T_xx00FC_rker “Vize@Weltmeister” → Vize_x0040_Weltmeister “ ” → _x003C_WM_Dritter_x002A_ Überführungsstrasse → _x00DC_berf_x00FC_hrungstrasse

17 Mapping from SQL - Data Types to XML-Schema Names Mapping of predefined data types: SQL-data typeXML-schema type BOOLEANboolean CHAR, VARCHAR, CLOBstring BIT, VARYING BIT, BLOBbase64Binary, hexBinary SMALLINT, INT, BIGINTinteger NUMERIC, DECIMALdecimal FLOAT, REAL, DOUBLE PRECISIONfloat, double DATEdate TIMEtime TIMESTAMPdateTime INTERVALduration  XML-schema type must be restricted, when its range exceeds its correspondent SQL-data type’s range. Example: VARCHAR(20) → maxLength(20)

18  Examples:  CHAR(20) <sqlxml:sqltype kind=“PREDEFINED” name=“CHAR” length=“20” characterSetName=“LATIN1” collation=“DEUTSCH”/>

19  NUMERIC(12,2) <sqlxml:sqltype kind=“PREDEFINED” name=“NUMERIC” userPrecision=“12” scale=“2”/>

20  SMALLINT <sqlxml:sqltype kind=“PREDEFINED” name=“SMALLINT”/>

21 Mapping of domains  mapped to XML-schema types that describe them as precisely as possible  example: CREATE DOMAIN ETH.DBS.Jobs CHAR(4) DEFAULT ‘Hiwi’ CHECK (VALUE IN (‘Prof’, ‘Assi’, ‘Hiwi’)) <sqlxml:sqltype kind=“DOMAIN” catalogName=“ETH” schemaName=“DBS” typeName=“Jobs” mappedType=“CHAR_4”/>

22 Mapping of the row type  mapped to complex type: each SQL-attribute represents an XML-element  the types of these elements is the result of mapping each attribute’s data type  example: ROW(FirstName CHAR(20), LastName CHAR(30)) <sqlxml:field name=“LastName” mappedType=“CHAR_30”/>

23 Mapping of collection types  mapped to complex type made up of a sequence with a single element  the type of this element is the result of mapping the appropriate SQL-data type  facets:  minOccurs=0  maxOccurs: array type: restricted by the maximal cardinality of the type multiset: unrestricted  examples:  DECIMAL(12,2) ARRAY[10] <sqlxml:sqltype kind=“ARRAY” maxElements=“10” mappedElementType=“NUMERIC_12_2”/> <xsd:element name=“Element” type=“NUMERIC_12_2” minOccurs=“0” maxOccurs=“10”/>

24  CHAR(20) MULTISET <sqlxml:sqltype kind=“MULTISET” mappedElementType=“CHAR_20”/> <xsd:element name=“Element” type=“CHAR_20” minOccurs=“0” maxOccurs=“unbounded”/>

25 Mapping of distinct types  directly identifies the appropriate SQL-source type  example: CREATE TYPE ETH.DBS.Franken AS NUMERIC(12,2) FINAL <sqlxml:sqltype kind=“DISTINCT” catalogName=“ETH” schemaName=“DBS” typeName=“Franken” mappedType=“Numeric_12_2” final=“true”/>

26 Mapping from SQL-tables to XML-documents Data and metadata are mapped separately:  XML-schema document : describes the schema of the table (name and type of columns, row type, type of the table)  XML-document : the content of the table Example: CREATE TABLE ETH.DBS.Employee {Name CHAR(20) NOT NULL, Salary NUMERIC(12,2)} the XML-schema document: <xsd:element name=“Name” type=“CHAR_20”/> <xsd:element name=“Salary” type=“NUMERIC_12_2” nillable=“true”/>

27 <sqlxml:sqlname type=“BASE TABLE” catalogName=“ETH” schemaName=“DBS” localName=“EMPLOYEE”/> <xsd:element name=“row” type=“ROW.ETH.DBS.EMPLOYEE” minOccurs=“0” maxOccurs=“unbounded”/>

28 the XML-document: Blum 3000 Black 7000

29 Mapping from SQL-Schema to XML-documents Data and metadata are mapped separately:  XML-schema document : definition of the schema and schema objects  XML-document : the content of the tables contained by the schema Example: CREATE SCHEMA ETH.DBS CREATE TABLE EMPLOYEE{Name CHAR(20) NOT NULL, Salary NUMERIC(12,2)} <sqlxml:sqlname type=“SCHEMA” catalogName=“ETH” schemaName=“DBS”/> <xsd:element name=“EMPLOYEE” type=“TABLE.ETH.DBS.EMPLOYEE”/>

30 Mapping from SQL-Catalogues to XML-documents Data and metadata are mapped separately:  XML-schema document: the definitions of the schemes contained by the catalogue  XML-document : the content of the tables contained by these schemes Example: <sqlxml:sqlname type=“CATALOG” catalogName=“ETH”/> <xsd:element name=“DBS” type=“SCHEMA.ETH.DBS”/>


Download ppt "SQL/XML Was sagt die Norm?. History SQL-86  the first version of the Structured Query Language Standard: -ANSI 1986 -ISO 1987  provides: -the notion."

Similar presentations


Ads by Google