Chapter09

Chapter09 - Copyright 2007 Ramez Elmasri and Shamkant B....

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Slide 9- 1 Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 9 Introduction to SQL Programming Techniques
Background image of page 2
Slide 9- 3 Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter Outline 9.1 General Constraints as Assertions 9.2 Views in SQL 9.3 Database Programming 9.4 Embedded SQL 9.5 Functions Calls, SQL/CLI 9.6 Stored Procedures, SQL/PSM 9.7 Summary
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Slide 9- 4 Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe 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, C++, etc.
Background image of page 4
Slide 9- 5 Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe 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
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Slide 9- 6 Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe 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’’ CREAT 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)) constraint name , CHECK , condition
Background image of page 6
Slide 9- 7 Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe 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
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Slide 9- 8 Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe SQL Triggers Objective: to monitor a database and take initiate action when a condition occurs Triggers are expressed in a syntax similar to assertions and include the following: Event Such as an insert, deleted, or update operation Condition Action To be taken when the condition is satisfied
Background image of page 8
Slide 9- 9 Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe SQL Triggers: An Example A trigger to compare an employee’s salary to his/her supervisor during insert or update operations: CREATE TRIGGER INFORM_SUPERVISOR BEFORE INSERT OR UPDATE OF SALARY, SUPERVISOR_SSN ON EMPLOYEE FOR EACH ROW WHEN ( NEW.SALARY> (SELECT SALARY FROM EMPLOYEE WHERE SSN=NEW.SUPERVISOR_SSN)) INFORM_SUPERVISOR (NEW.SUPERVISOR_SSN,NEW.SSN);
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Slide 9- 10 Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe 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
Background image of page 10
Slide 9- 11 Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 42

Chapter09 - Copyright 2007 Ramez Elmasri and Shamkant B....

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online