Advanced SQL

Advanced SQL

AdvSQL Advanced SQL Sources: [Mel02] Melton & Simon: SQL:1999 Understanding Relational Language Components, 2002 [Con02] Connolly & Begg: Database Systems, 3rd ed, 2002 [Gul99] Gulutzan & Pelzer: SQL-99 Complete, Really, 1999 [Cel99] Joe Celko: SQL for Smarties, 2nd ed, 1999 Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Standards, Specs, Implementations, .. See [Con02] • SQL Standards chapter 5 – ANSI X3.135-1986, X3.168-1989 (ESQL), X3.135-1989 (IEF) – ISO/IEC 9075:1992 (SQL-92), 9075:1999 (SQL:1999), 9075:2003 (SQL:2003), 9075:2006 (SQL:2006), .. – FIPS PUB 127-2 (see http://www.ocelot.ca/) • Specifications – IBM SAA / SQL – X/Open • Implementations (dialects) – Vendors: IBM, Oracle, .. • Related standards – ISO IRDS – ISO RDA – X/Open XA Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL:1999 Parts and Conformances (SQL:2003) [Gul99] • Part 1: SQL/Framework - fundamental concepts • Part 2: SQL/Foundation - syntax and operations • Part 3: SQL/Call-Level Interface - function library • Part 4: SQL/Persistent Stored Modules • Part 5: SQL/Host Language Bindings - ESQL – Ada, C, Cobol, Fortran, Mumps, Pascal, PL/I – (note: not included in SQL:2003) • Minimal Conformance – Core SQL Support • Enhanced Conformance – SQL Packages – SQL Flagger Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Parts of SQL:2003 • 9075-1 SQL/Framework • 9075-2 SQL/Foundation • 9075-3 SQL/CLI • 9075-4 SQL/PSM • 9075-9 SQL/MED • 9075-10 SQL/OLB • 9075-11 SQL/Schemata • 9075-13 SQL/JRT • 9075-14 SQL/XML Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL:1999 Packages [Gul99] [Mel02] • Enhanced datetime facility package • Enhanced integrity management package • OLAP facilities package • PSM package • CLI package (call-level interface) • Basic object support package • Enhanced object support package • Active database package • SQL/MM package (multimedia) Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL Flagger [Gul99] Flags non-conforming extensions • Core SQL Flagging • Part SQL Flagging • Package SQL Flagging • Syntax Only • Catalog Lookup - syntax and access violations – INFORMATION_SCHEMA (Compare with FIPS-127 flagger) Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL Statement Classes [Gul99] • SQL-Schema statements (DDL) – CREATE / ALTER / DROP ... • SQL-data statements (~ DML) – INSERT, UPDATE, DELETE, SELECT, cursor management • SQL-transaction statements – START TRANSACTION, SET TRANSACTION, COMMIT, ... • SQL-control statements – CALL, RETURN • SQL-connection statements – CONNECT, SET CONNECTION, DISCONNECT • SQL-session statements – SET TIME ZONE, SET ROLE, SET SESSION ... • SQL-diagnostics statements – GET DIAGNOSTICS Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Terminology & Concepts ISO SQL-92, SQL:1999: • SQL Environment • SQL Objects • Schema objects hierarchy: [ [catalog.]schema .]object • Connection objects, Session objects • SQL Datatypes • SQL Language Implementation concepts only: • Database, Indexes, ... Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL Object name classes • Cluster • Character Set • <AuthorizationID> • Collation • Privilige • Translation • Catalog • Trigger • Schema • Module • Table • SQL-invoked routine • View – procedure • Column – function • Domain and UDT • Constraint and Assertion Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Name class hierarchy (draft) Physical Server DB Instance (Database) Catalog AuthorizationID Schema Domain / UDT Table / View SQL-Routine Trigger Procedure Function Column Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL-92 Definition Schema - just for defining the Information Schema views as part of the standard! Users Check_constraints Schemata Check_table_usage Data_Type_Descriptor Check_column_usage Domains Assertions Tables Table_privileges Views Column_privileges Columns Usage_privileges View_table_usage Character_sets View_column_usage Collations Table_constraints Translation Key_column_usage SQL_languages Referential_constraint Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL-92 Information Schema - Implemetations should provide these DBMS independent views Applicable_Roles Check_constraints Schemata Assertions Data_Type_Privileges Table_privileges Domains Usage_privileges Tables Character_sets Views Collations Columns Translations View_table_usage SQL_Languages View_column_usage SQL_Features Table_constraints … Key_column_usage Referential_constraints Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL Datatypes Pre-defined datatypes: Constructed datatypes: • Number types • reference types • Bit String types • locators • Binary String types • row types • Character String types • collection types • Temporal types (arrays) • Boolean types • User-defined types Haaga-Helia, Martti Laiho 1997-2007 AdvSQL … Data types See [Con02] chapter 6 • Boolean data – Boolean • Character data – Char[acter], Character Varying (Varchar), NChar, NVarchar,.. • Bit data – Bit, Bit varying (not included in SQL:2003) • Exact numeric data – Integer, Smallint, Numeric, Decimal • Approximate numeric data – Float, Real, Double precision • Temporal data – Datetime data: Date, Time, Timestamp .. [WITH TIME ZONE] – Interval Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Literals • Character 'some text' • National character [varying] N'ÅäöÆçÐĦ' 'ﻕﺥﺖﺁ'N • Integer 12345 • Smallint 12 • Numeric 1.234 123 • Decimal 1.234 • Float 1.23E3 1.23E-2 • Real 1.23E3 1.23E-2 • Bit [varying] B'01011111' (deleted in 2001) X'5F' Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Integrity Enhancement Feature (IEF) • Required data - Not Null • DOMAIN integrity • Entity integrity (EI) - Primary Key, Unique • Referential integrity (RI) - Foreign Key referential actions ON UPDATE / ON DELETE: – No Action – Cascade – Set NULL – Set Default • Enterprise constraints Assertions Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Create / Alter / Drop object DROP … [ RESTRICT | CASCADE ] CASCADE: Drops also the related objects RESTRICT: Drop command fails if related objects exist Note: implementations may differ Haaga-Helia, Martti Laiho 1997-2007 AdvSQL CREATE DOMAIN Syntax: CREATE DOMAIN <domain name> [AS] <data type> [ DEFAULT <default value> ] [ <domain constraint> ... ] [ COLLATE <collation name> ] <domain constraint> ::= [CONSTRAINT <constraint name> ] CHECK (<predicate> ) [ <constraint attributes> ] <constraint attributes> ::= NOT DEFERRABLE | DEFERRABLE [INITIALLY IMMEDIATE] Note: no implementations in mainstream products! Haaga-Helia, Martti Laiho 1997-2007 AdvSQL CREATE TABLE CREATE [ { GLOBAL | LOCAL} TEMPORARY] TABLE <table_name> ( <table element list> ) [ ON COMMIT {PRESERVE ROWS | DELETE ROWS} ] <table element> ::= <column definition> | < table constraint > | ... [Gul99] p 356 - Haaga-Helia, Martti Laiho 1997-2007 AdvSQL ALTER TABLE • ADD COLUMN ... • DROP COLUMN … [RESTRICT | CASCADE] • ALTER COLUMN .. SET DEFAULT .. • ALTER COLUMN .. DROP DEFAULT • ADD CONSTRAINT • DROP CONSTRAINT … [RESTRICT | CASCADE] See [Con02] 6.2 Haaga-Helia, Martti Laiho 1997-2007 AdvSQL CREATE VIEW [Con02] 6.4 [Gul99] p 376- • Syntax CREATE [RECURSIVE] VIEW <view_name> [ (column_name [, …] ) ] AS <query expression> [WITH [CASCADED | LOCAL] CHECK OPTION ] • Implementations: – View resolution, restrictions, updatablity – Macro: inline replacements – Materialized view into a hidden temporary base table Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Views Advantages Disadvantages • Data independence • Update restrictions • Currency • Structure restrictions – changes reflected immed. • Performance? • Improved Security • Reduced complexity • Convenience • Customization • Data integrity See [Con02] chapter 6.4.7 – With Check Option Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Materialized Views Advantages Disadvantages • Data independence • Update restrictions • Currency • Structure restrictions – changes reflected immed. • Performance? • Improved Security • Reduced complexity • Convenience • Customization • Data integrity See [Con02] chapter 6.4.7 – With Check Option Haaga-Helia, Martti Laiho 1997-2007 AdvSQL CREATE ASSERTION Syntax: CREATE ASSERTION <constraint name> CHECK (<predicate> ) [ <constraint attributes> ] Note: no implementations in mainstream products! Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Numeric Value Functions [Mel02] • ABS ( numeric-value ) • BIT_LENGTH ( string-value ) • OCTET_LENGTH ( string-value ) • CHAR_LEGTH ( character-string ) • CARDINALITY ( collection-value ) • POSITION ( string-value IN string-value ) • EXTRACT ( datetime-field FROM datetime-value ) • EXTRACT ( datetime-field FROM interval-value ) • EXTRACT ( timezone-field FROM datetime-value ) • MOD ( numeric-dividend , numeric-divisor ) Haaga-Helia, Martti Laiho 1997-2007 AdvSQL String Value Functions / Operators [Mel02] • SUBSTRING ( string-value FROM start [ FOR length ] ) • SUBSTRING ( string-value SIMILAR string-value ESCAPE character-value ) • UPPER ( character-string-value ) • LOWER ( character-string-value ) • TRIM ( [ BOTH | LEADING | TRAILING ] character FROM character-string-value ) • TRANSLATE ( character-string-value USING translation ) • CONVERT ( character-string-value USING conversion ) • OVERLAY (string-value PLACING string-value FROM start [ FOR length ] ) • string-value || string-value Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Built-in Scalar Operators/functions • USER • CURRENT_USER • SESSION_USER • SYSTEM_USER • CURRENT_ROLE • CURRENT_PATH Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Datetime Value Functions [Mel02] • CURRENT_DATE • CURRENT_TIME [ ( precision ) ] • CURRENT_TIMESTAMP [ ( precision ) ] • LOCALTIME [ ( precision ) ] • LOCALTIMESTAMP [ ( precision ) ] Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Temporal

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    29 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us