SQL:2003 An Introduction to Some New Features. New Data Types BIT and BIT VARYING removed BIGINT, MULTISET and XML introduced –First class data types:

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

The Relational Model. Introduction Introduced by Ted Codd at IBM Research in 1970 The relational model represents data in the form of table. Main concept.
Stored Procedure Language Stored Procedure Overview Stored Procedure is a function in a shared library accessible to the database server can also write.
Database Design -- Basic SQL
Chapter 5 Types. 5-2 Topics in this Chapter Values vs. Variables Types vs. Representations Type Definition Operators Type Generators SQL Facilities.
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 SQL: Data Definition, Constraints, and Basic Queries and Updates.
1 Query Languages: How to build or interrogate a relational database Structured Query Language (SQL)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
SQL Neyha Amar CS 157A, Fall Inserting The insert statement is used to add a row of data into a table Strings should be enclosed in single quotes,
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
SQL SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against.
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
Database Systems More SQL Database Design -- More SQL1.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
SQL Operations Aggregate Functions Having Clause Database Access Layer A2 Teacher Up skilling LECTURE 5.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
Introduction to SQL  SQL or sequel  It is a standardised language with thousands of pages in the standard  It can be in database system through GUI,
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 13 Managing Databases with SQL Server 2000.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
CSE314 Database Systems Lecture 4 Basic SQL Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 8 Advanced SQL.
Introduction to Databases Chapter 7: Data Access and Manipulation.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
WG3 Database Languages Stephen Cannan Convenor
Lecture 17 Object relational databases. 2 Example Table Creation based on UDT CREATE TABLE Person ( info PersonType, CONSTRAINT DOB_Check CHECK(dateOfBirth.
Overview of Standard Query Language (SQL) Saeideh Joodaki Instructor: Dr.Yingshu Li.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 DB2 9 Fundamentals.
Chapter 2 Adapted from Silberschatz, et al. CHECK SLIDE 16.
Other database objects (Sequence). What Is a Sequence? A sequence: Automatically generates sequential numbers Is a sharable object Is typically used to.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Stored Procedures Week 9. Test Details Stored Procedures SQL can call code written in iSeries High Level Languages –Called stored procedures SQL has.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Collections Oracle Database PL/SQL 10g Programming Chapter 6.
SQL: Advanced topics Prof. Weining Zhang Cs.utsa.edu.
Advanced SQL: Triggers & Assertions
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
Database Programming Sections 11 & 12 –Sequences, Indexes, and Synonymns.
1 Notes on: Clusters Index and Cluster Creation in SQL Elisa Bertino CS Department and CERIAS Purdue University.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
Topics Related to Attribute Values Objectives of the Lecture : To consider sorting relations by attribute values. To consider Triggers and their use for.
Chapter 4 An Introduction to SQL. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.4-2 Topics in this Chapter SQL: History and Overview The.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Query Processing – Implementing Set Operations and Joins Chap. 19.
Module 10 Merging Data and Passing Tables. Module Overview Using the MERGE Statement Implementing Table Types Using Table Types As Parameters.
1 SQL Chapter 9 – 8 th edition With help from Chapter 2 – 10 th edition.
Chapter 8 Advanced SQL. Relational Set Operators UNIONINTERSECTMINUS Work properly if relations are union- compatible –Names of relation attributes must.
SQL Triggers, Functions & Stored Procedures Programming Operations.
 CONACT UC:  Magnific training   
V6R1 – Database enhancements DECFLOAT data type BX literals FOR BIT DATA and binary compatibility Client special registers Grouping Sets and Super groups.
BTM 382 Database Management Chapter 8 Advanced SQL Chitu Okoli Associate Professor in Business Technology Management John Molson School of Business, Concordia.
1. Advanced SQL Functions Procedural Constructs Triggers.
Chapter 4 An Introduction to SQL. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.4-2 Topics in this Chapter SQL: History and Overview The.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
More SQL: Complex Queries,
Tuning Transact-SQL Queries
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Instructor: Craig Duckett Lecture 09: Tuesday, April 25th, 2017
Database Systems: Design, Implementation, and Management Tenth Edition
Object-Relational DBMSs
Using the Set Operators
CS 405G: Introduction to Database Systems
Chapter 5 Sequences.
CMPT 354: Database System I
Chapter 8 Advanced SQL.
Database Systems: Design, Implementation, and Management Tenth Edition
Presentation transcript:

SQL:2003 An Introduction to Some New Features

New Data Types BIT and BIT VARYING removed BIGINT, MULTISET and XML introduced –First class data types: can be used in all the contexts that any other (existing) SQL data type can be used; e.g. as column types, parameter and return types of SQL-revoked routines, etc

MULTISET(1) MULTISET: unordered collection of elements, all of the same element type, with duplicates permitted. –SQL:1999 only has ARRAY –Element type: any SQL data type, including another collection type, e.g. INTEGER MULTISET –Unbounded

MULTISET(2) Value creation for MULTISET –Enumeration: MULTISET [1,2,3,4] –Query: MULTISET (SELECT grade FROM courses) A multiset value can be used as a table reference in FROM using UNNEST operator, e.g. SELECT T.A, T.A*2 AS B FROM UNNEST(MULTISET [1,2,3,4]) AS T(A)

MULTISET(3) Operations supported by MULTISET –Casting a multiset into an array or another multiset with a compatible element type –Removing duplicates from a multiset –Returning the number of elements in a given multiset –Returning the only element of a multiset that has exactly one element –Union, intersection, difference –Three new aggregate functions –Predicates: test =, , , , etc

New multiset aggregate functions COLLECT: create a multiset from the value of the argument in each row of a group FUSION: create a multiset union of a multiset value in all rows of a group INTERSECTION: create a multiset intersection of a multiset value in all rows of a group

Examples SELECT COLLECT(A) AS all_A, FUSION(B) AS all_B, INTERSECTION(B) AS common_B FROM R; R: A B a multiset[1,2] b multiset[1] c multiset[1,3] Result: all_A all_B common_B multiset[a,b,c] multiset[1,1,1,2,3] multiset[1]

Table Functions SQL-invoked function that returns a “table” –Not a real table, but a MULTISET type with ROW type element –Can be queried like a table

Table Functions – Example (1) CREATE FUNCTION func( ) RETURNS TABLE (A CHAR(10), B INT) LANGUAGE SQL //body written in SQL READS SQL DATA //read-only access to DB DETERMINISTIC //same input/DB state -> same result RETURN TABLE( SELECT name, age FROM student); To invoke func( ): SELECT T.A FROM TABLE(func( )) AS T WHERE T.B>20;

Table Functions – Example(2) CREATE FUNCTION external_func( ) RETURNS TABLE (A VARCHAR(10), B INT) NOT DETERMINISTIC //same input, different results NO SQL //not call back to SQL engine to exec SQL LANGUAGE C EXTERNAL PARAMETER STYLE SQL; //associated with null indicator How is external_func( ) invoked by the SQL engine? –Open call: once. Set up data structures –Fetch call: multiple invocations. One row transmitted per invocation. –Close call: once.

CREATE TABLE LIKE (1) SQL:1999 allows copying table structure into new table – but restricted to column name and type CREATE TABLE T1 ( C1 INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 2), C2 VARCHAR(100) NOT NULL DEFAULT ‘test’); CREATE TABLE T2 ( LIKE T1, C3 CHAR(50)); CREATE TABLE T3 ( C1 INTEGER, C2 VARCHAR(100), C3 CHAR(50)); –T2 is equivalent to T3

CREATE TABLE LIKE (2) SQL:2003 introduced additional (optional) options for the LIKE clause for copying more information CREATE TABLE T1 ( C1 INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 2), C2 VARCHAR(100) NOT NULL DEFAULT ‘test’); CREATE TABLE T4 ( LIKE T1 INCLUDING COLUMN DEFAULTS INCLUDING INDENTITY); –T4 is equivalent to T1

CREATE TABLE AS Create a table from a query CREATE TABLE T5 (D1, D2, D3, D4) AS ( SELECT T1.C1, T1.C2, T2.C3 FROM T1, T2 WHERE T1.C2 = T2.C2) WITH DATA; –Similar to materialized query tables(MQT) or materialized views? –No dependency

MERGE Transfer data from “transaction table” to a “master table” –TT contains Updates to the existing rows in the MT New rows that should be inserted into the MT –MERGE = UPDATE + INSERT

MERGE -- Example Inventory(before) Shipment Inventory(after) PART DESC QTY PART DESC QTY PART DESC QTY 1 AAA 10 2 BBB 5 1 AAA 20 2 BBB 15 4 DDD 15 2 BBB 20 3 CCC 20 1 AAA 10 3 CCC 20 4 DDD 15 MERGE INTO Inventory AS I USING (SELECT PART,DESC,QTY FROM Shipment) AS S ON (I.PART = S.PART) WHEN MATCHED THEN UPDATE SET QTY=I.QTY+S.QTY WHEN NOT MATCHED THEN INSERT (PART,DESC,QTY) VALUES (S.PART, S.DESC, S.QTY)

Sequence Generator Used for generating unique values automatically –New kind of DB object Example CREATE SEQUENCE PartSeq AS INTEGER START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE NO CYCLE INSERT INTO Shipment VALUES (NEXT VALUE FOR PartSeq, ‘EEE’, 20);

Identity Columns Similar to sequence generator, but value is automatically generated Example CREATE TABLE Parts ( PART INTEGER GENERATED ALWAYS AS INDENTITY (START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE NO CYCLE), DESC VARCHAR(100), QTY INTEGER); INSERT INTO Parts(DESC,QTY) VALUES(‘FFF’,30);

Generated Columns A generated column is associated with a scalar expression that evaluate the value for that column Example CREATE TABLE Employees ( EMPID INTEGER, SALARY DECIMAL(7,2), BONUS DECIMAL(7,2), TOTAL_COMP GENERATED ALWAYS AS (SALARY + BONUS)) INSERT INTO Employees(EMPID,SALARY,BONUS) VALUES(501, , );