Chapter 7 SQL HUANG XUEHUA. Chapter Objectives Specification of more general constraints via assertions SQL facilities for defining views (virtual.

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

Basic SQL Introduction Presented by: Madhuri Bhogadi.
1 Constraints, Triggers and Active Databases Chapter 9.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 9 Introduction to SQL Programming Techniques.
SQL Constraints and Triggers
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Objective: To access a database from an application program (as opposed to interactive interfaces) Why? An interactive interface is convenient but not.
Dec 4, 2003Murali Mani SQL B term 2004: lecture 14.
METU Department of Computer Eng Ceng 302 Introduction to DBMS SQL: Assertions, Views, and Programming Techniques by Pinar Senkul resources: mostly froom.
Introduction to Structured Query Language (SQL)
Database Systems More SQL Database Design -- More SQL1.
View and Materialized view. What is a view? Logically represents subset of data from one or more table. In sql, a view is a virtual relation based on.
Introduction to Structured Query Language (SQL)
More SQL: Complex Queries, Triggers, Views, and Schema Modification 1.
Introduction to Oracle9i: SQL1 Views. Introduction to Oracle9i: SQL2 Chapter Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE.
Chapter 9 MORE SQL: Assertions, Views, and Programming Techniques Copyright © 2004 Pearson Education, Inc.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Advanced Database CS-426 Week 2 – Logic Query Languages, Object Model.
Chapter 6: Integrity and Security Thomas Nikl 19 October, 2004 CS157B.
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.
Chapter 9 MORE SQL: Assertions, Views, and Programming Techniques Copyright © 2004 Pearson Education, Inc.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 9- 1 DATADABASE PROGRAMMING 2Chapter 13 from our text.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Chapter 3 MORE SQL Copyright © 2004 Pearson Education, Inc.
SQL: Schema Definition, Constraints, & Queries and Views.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Lecture # 11 July 12,2012 More SQL: Complex Queries, Triggers,
+ Constraints and triggers: maintaining the ACID properties of transactions CSCI 2141 W2013 Slides from:
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
EXAM 1 NEXT TUESDAY…. EXAMPLE QUESTIONS 1.Why is the notion of a “state” important in relational database technology? What does it refer to? 2.What do.
Information Building and Retrieval Using MySQL Track 3 : Basic Course in Database.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
DATABASE VIEWS CHAPTER 5 (6/E) CHAPTER 8 (5/E) 1.
IS 230Lecture 6Slide 1 Lecture 7 Advanced SQL Introduction to Database Systems IS 230 This is the instructor’s notes and student has to read the textbook.
Chapter 3 MORE SQL Copyright © 2004 Pearson Education, Inc.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Chapter 6 MORE SQL: Assertions, Views, and Programming Techniques Copyright © 2004 Pearson Education, Inc.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Chapter 7 SQL HUANG XUEHUA. AGGREGATE FUNCTIONS Include COUNT, SUM, MAX, MIN, and AVG Query 15: Find the maximum salary, the minimum salary, and the.
Chapter 8 Part 2 SQL-99 Schema Definition, Constraints, Queries, and Views.
Advanced SQL: Triggers & Assertions
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
1 CS 430 Database Theory Winter 2005 Lecture 14: Additional SQL Topics.
Chapter 13 Views Oracle 10g: SQL. Oracle 10g: SQL2 Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE VIEW command Employ the.
DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 1.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 & 9 SQL-99: SchemaDefinition, Constraints, Introduction to SQL Programming Techniques.
ISC321 Database Systems I Chapter 5: SQL: Advanced Queries, Assertions, Triggers, and Views Fall 2015 Dr. Abdullah Almutairi.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
SQL Triggers, Functions & Stored Procedures Programming Operations.
SQL- Updates, Assertions and Views. Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations)
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Copyright © 2004 Pearson Education, Inc.. Chapter 24 Enhanced Data Models for Advanced Applications.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
Structured Query Language (3) The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems,
10/3/2017.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Introduction to SQL Programming Techniques
Chapter 6 - Database Implementation and Use
Views, Stored Procedures, Functions, and Triggers
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
Subject Name: DATABASE MANAGEMENT SYSTEM Subject Code: 10CS54
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Advanced SQL: Views & Triggers
Introduction to SQL Programming Techniques
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Structured Query Language (3)
So What are Views and Triggers anyway?
SQL Views Presented by: Dr. Samir Tartir
Presentation transcript:

Chapter 7 SQL HUANG XUEHUA

Chapter Objectives Specification of more general constraints via assertions SQL facilities for defining views (virtual tables) Various techniques for accessing and manipulating a database via programs in general- purpose languages (e.g., Java)

Constraints as Assertions General constraints: constraints that do not fit in the basic SQL categories (presented in chapter 8) Mechanism: CREAT ASSERTION  components include: a constraint name, followed by CHECK, followed by a condition

Assertions: An Example “The salary of an employee must not be greater than the salary of the manager of the department that the employee works for’’ CREATE ASSERTION SALARY_CONSTRAINT CHECK (NOT EXISTS (SELECT * FROM EMPLOYEE E, EMPLOYEE M, DEPARTMENT D WHERE E.SALARY > M.SALARY AND E.DNO=D.NUMBER AND D.MGRSSN=M.SSN))

Using General Assertions Specify a query that violates the condition; include inside a NOT EXISTS clause Query result must be empty  if the query result is not empty, the assertion has been violated

SQL Triggers Objective: to monitor a database and take action when a condition occurs Triggers are expressed in a syntax similar to assertions and include the following:  event (e.g., an update operation)  condition  action (to be taken when the condition is satisfied)

SQL Triggers: An Example A trigger to compare an employee’s salary to his/her supervisor during insert or update operations: REATE TRIGGER reminder1 ON employee AFTER INSERT, UPDATE AS RAISERROR ('Notify Customer Relations', 16, 10) GO

Views in SQL A view is a “virtual” table that is derived from other tables Allows for limited update operations (since the table may not physically be stored) Allows full query operations A convenience for expressing certain operations

Specification of Views SQL command: CREATE VIEW  a table (view) name  a possible list of attribute names (for example, when arithmetic operations are specified or when we want the names to be different from the attributes in the base relations)  a query to specify the table contents

SQL Views: An Example Specify a different WORKS_ON table CREATE VIEW WORKS_ON_NEW AS SELECT FNAME, LNAME, PNAME, HOURS FROM EMPLOYEE, PROJECT, WORKS_ON WHERE SSN=ESSN AND PNO=PNUMBER GROUP BY PNAME;

Using a Virtual Table We can specify SQL queries on a newly create table (view): SELECT FNAME, LNAME FROM WORKS_ON_NEW WHERE PNAME=‘Seena’; When no longer needed, a view can be dropped: DROP VIEW WORKS_ON_NEW;

Efficient View Implementation (1) Query modification: present the view query in terms of a query on the underlying base tables  disadvantage: inefficient for views defined via complex queries (especially if additional queries are to be applied to the view within a short time period)

Efficient View Implementation (2) View materialization: involves physically creating and keeping a temporary table  assumption: other queries on the view will follow  concerns: maintaining correspondence between the base table and the view when the base table is updated  strategy: incremental update

View Update Update on a single view without aggregate operations: update may map to an update on the underlying base table Views involving joins: an update may map to an update on the underlying base relations  not always possible

Un-updatable Views Views defined using groups and aggregate functions are not updateable Views defined on multiple tables using joins are generally not updateable WITH CHECK OPTION : must be added to the definition of a view if the view is to be updated  to allow check for updatability and to plan for an execution strategy

Database Programming Objective: to access a database from an application program (as opposed to interactive interfaces) Why? An interactive interface is convenient but not sufficient; a majority of database operations are made thru application programs (nowadays thru web applications)

Database Programming Approaches Embedded commands: database commands are embedded in a general-purpose programming language Library of database functions: available to the host language for database calls; known as an API A brand new, full-fledged language (minimizes impedance mismatch)