Chapter 8 Advanced SQL. Relational Set Operators UNIONINTERSECTMINUS Work properly if relations are union- compatible –Names of relation attributes must.

Slides:



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

The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
TURKISH STATISTICAL INSTITUTE 1 /34 SQL FUNDEMANTALS (Muscat, Oman)
1 Constraints, Triggers and Active Databases Chapter 9.
Foundations of Relational Implementation n Defining Relational Data n Relational Data Manipulation n Relational Algebra.
Databases. Database Information is not useful if not organized In database, data are organized in a way that people find meaningful and useful. Database.
Structured Query Language (SQL)
Sequence Sen Zhang. The AutoNumber data type stores an integer that Access increments (adds to) automatically as you add new records. You can use the.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Fundamentals, Design, and Implementation, 9/e Chapter 7 Using SQL in Applications.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
A Guide to SQL, Seventh Edition. Objectives Embed SQL commands in PL/SQL programs Retrieve single rows using embedded SQL Update a table using embedded.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
Transforming Data Models into Database Designs
SQL's Data Definition Language (DDL) – View, Sequence, Index.
SQL Within PL / SQL Chapter 4. 2 SQL Within PL / SQL SQL Statements DML in PL / SQL Pseudocolums Transaction Control.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 8 Advanced SQL.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 8 Advanced SQL.
Database Technical Session By: Prof. Adarsh Patel.
Introduction to SQL Steve Perry
STORING ORGANIZATIONAL INFORMATION— DATABASES CIS 429—Chapter 7.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
Advanced SQL Advanced SQL Complex Queries, Joining Tables.
Component 4: Introduction to Information and Computer Science Unit 6: Databases and SQL Lecture 3 This material was developed by Oregon Health & Science.
Component 4/Unit 6c Topic III Structured Query Language Background information What can SQL do? How is SQL executed? SQL statement characteristics What.
CS 1308 Computer Literacy and the Internet
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Chapter 6 Procedural Language SQL and Advanced SQL Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
3 3 Chapter 3 Structured Query Language (SQL) Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Database Technology Jing Shen.
Commercial RDBMSs Access and Oracle. Access DBMS Architchecture  Can be used as a standalone system on a single PC: -JET Engine -Microsoft Data Engine.
Chapter 9 Databases Objectives Understand a DBMS and define its components. Understand the architecture of a DBMS and its levels. Distinguish between.
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures.
Assertions and triggers1. 2 Constraints Attribute-based CHECK constraints create table … ( postcode number(4) check (postcode > 0) ); Checked at update.
1 Chapter 1 File Systems and Databases Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel l 工程資料庫專題 –NTUST/ME-2007Q4.
Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Week 4 Lecture Part 2 of 3 Structured Query Language (SQL) Samuel ConnSamuel Conn, Faculty Suggestions for using the Lecture Slides.
Commercial RDBMSs: Office Access and Oracle Pertemuan 13 Matakuliah: M0564 /Pengantar Sistem Basis Data Tahun : 2008.
10 1 Chapter 10 - A Transaction Management Database Systems: Design, Implementation, and Management, Rob and Coronel.
Chapter 3: Relational Databases
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
BTM 382 Database Management Chapter 8 Advanced SQL Chitu Okoli Associate Professor in Business Technology Management John Molson School of Business, Concordia.
SQL Basics Review Reviewing what we’ve learned so far…….
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.
Agenda for Today  DATABASE Definition What is DBMS? Types Of Database Most Popular Primary Database  SQL Definition What is SQL Server? Versions Of SQL.
A Guide to SQL, Seventh Edition
Database Systems: Design, Implementation, and Management Tenth Edition
ITEC 313 Database Programming
Database Fundamentals
CSCI 2141 – Intro to Database Systems
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Processing: David M. Kroenke’s Chapter Seven:
Chapter 7 Using SQL in Applications
Chapter 7 Using SQL in Applications
Chapter 8 Advanced SQL.
Database Systems: Design, Implementation, and Management Tenth Edition
Chapter 11 Managing Databases with SQL Server 2000
Presentation transcript:

Chapter 8 Advanced SQL

Relational Set Operators UNIONINTERSECTMINUS Work properly if relations are union- compatible –Names of relation attributes must be the same and their data types must be identical

UNION Example query: –SELECT CUS_LNAME, CUS_FNAME, CUS_INITIAL, CUS_AREACODE, CUS_PHONE FROM CUSTOMER UNION SELECT CUS_LNAME, CUS_FNAME, CUS_INITIAL, CUS_AREACODE, CUS_PHONE FROM CUSTOMER_2; The resulting data would be all rows from both tables (with no duplicates)

UNION ALL Example query: –SELECT CUS_LNAME, CUS_FNAME, CUS_INITIAL, CUS_AREACODE, CUS_PHONE FROM CUSTOMER UNION ALL SELECT CUS_LNAME, CUS_FNAME, CUS_INITIAL, CUS_AREACODE, CUS_PHONE FROM CUSTOMER_2; The resulting data would be all rows from both tables (with duplicates)

INTERSECT This returns only those rows that are in both tables (the duplicates)

MINUS This returns only rows that exist in the first table, but not in the second

Natural Joins Old style: SELECT P_PRODUCT, V_VENDOR SELECT P_PRODUCT, V_VENDOR FROM PRODUCT, VENDOR WHERE PRODUCT.V_CODE = VENDOR.V_CODE New style: SELECT P_PRODUCT, V_VENDOR SELECT P_PRODUCT, V_VENDOR FROM PRODUCT NATURAL JOIN VENDOR

Updatable Views Views that can be updated which will update their corresponding tables. Views can be updatable if the primary key of the base table is a column in the view that also has unique values

Sequences Pg. 318 Sequences are independent objects in the database They are considered “Auto-numbers” They are created and used as primary keys in tables where the key is a sequential number CREATE SEQUENCE Part_Num_Seq START WITH 100

Sequences on Insert Refer to the sequence (auto-number) object in place of the value needed for the key when inserting data into a table Can be used with NEXTVAL ( sequence is incremented ) or CURRVAL ( current value of sequence is used ) INSERT INTO PARTS VALUES ( PART_ID_SEQ.NEXTVAL, ‘PART_NAME, ect……..)

Procedural SQL Shortcomings of SQL –SQL doesn’t support execution of a stored set of procedures based on some logical condition. –SQL fails to support the looping operations. Solutions –Embedded SQL Embedded SQL can be called from within the procedural programming language –Shared Code Critical code is isolated and shared by all application programs.

Procedural SQL –Procedural SQL allows the use of procedural code and SQL statements that are stored within the database. –The procedural code is executed by the DBMS when it is invoked by the end user. –End users can use procedural SQL (PL/SQL) to create: Triggers Stored procedures PL/SQL functions Procedural SQL

Triggers page 328 –A trigger is procedural SQL code that is automatically invoked by the RDBMS upon the occurrence of a data manipulation event. A trigger is always invoked before or after a data row is selected, inserted, or updated. A trigger is always associated with a database table. Each database table may have one or more triggers. A trigger is executed as part of the transaction that triggered it. Procedural SQL

–Role of triggers Triggers can be used to enforce constraints that cannot be enforced at the design and implementation levels. Triggers add functionality by automating critical actions and providing appropriate warnings and suggestions for remedial action. Triggers can be used to update table values, insert records in tables, and call other stored procedures. Triggers add processing power to the RDBMS and to the database system.

Procedural SQL Stored Procedures –A stored procedure is a named collection of procedural and SQL statements. –Stored procedures are stored in the database and invoked by name. –Stored procedures are executed as a unit. –The use of stored procedures reduces network traffic, thus improving performance.

Stored Functions – is a named group of procedural and SQL statements that returns a value. –Invoked from within stored procedures or triggers –Cannot be invoked from within SQL statements PL/SQL Stored Functions