Chapter09

51
Chapter 9 MORE SQL: Assertions, Views, and Programming Techniques Copyright © 2004 Pearson Education, Inc.

description

Fundmental of db by Ramez elmasry

Transcript of Chapter09

Page 1: Chapter09

Chapter 9

MORE SQL: Assertions, Views, and Programming Techniques

Copyright © 2004 Pearson Education, Inc.

Page 2: Chapter09

Chapter 9-2Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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

Page 3: Chapter09

Chapter 9-3Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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)

Page 4: Chapter09

Chapter 9-4Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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

Page 5: Chapter09

Chapter 9-5Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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))

Page 6: Chapter09

Chapter 9-6Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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

Page 7: Chapter09

Chapter 9-7Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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)

Page 8: Chapter09

Chapter 9-8Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

SQL Triggers: An Example

A trigger to compare an employee’s salary to his/her supervisor during insert or update operations:

CREATE TRIGGER INFORM_SUPERVISORBEFORE INSERT OR UPDATE OF

SALARY, SUPERVISOR_SSN ON EMPLOYEEFOR EACH ROW

WHEN(NEW.SALARY> (SELECT SALARY FROM EMPLOYEE

WHERE SSN=NEW.SUPERVISOR_SSN))INFORM_SUPERVISOR (NEW.SUPERVISOR_SSN,NEW.SSN;

Page 9: Chapter09

Chapter 9-9Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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 operationsA convenience for expressing certain

operations

Page 10: Chapter09

Chapter 9-10Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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

Page 11: Chapter09

Chapter 9-11Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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;

Page 12: Chapter09

Chapter 9-12Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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;

Page 13: Chapter09

Chapter 9-13Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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)

Page 14: Chapter09

Chapter 9-14Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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

Page 15: Chapter09

Chapter 9-15Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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

Page 16: Chapter09

Chapter 9-16Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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

Page 17: Chapter09

Chapter 9-17Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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)

Page 18: Chapter09

Chapter 9-18Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

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)

Page 19: Chapter09

Chapter 9-19Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Impedance Mismatch

Incompatibilities between a host programming language and the database model, e.g.,– type mismatch and incompatibilities;

requires a new binding for each language– set vs. record-at-a-time processing

need special iterators to loop over query results and manipulate individual values

Page 20: Chapter09

Chapter 9-20Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Steps in Database Programming

1. Client program opens a connection to the database server

2. Client program submits queries to and/or updates the database

3. When database access is no longer needed, client program terminates the connection

Page 21: Chapter09

Chapter 9-21Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Embedded SQL

Most SQL statements can be embedded in a general-purpose host programming language such as COBOL, C, Java

An embedded SQL statement is distinguished from the host language statements by EXEC SQL and a matching END-EXEC (or semicolon)– shared variables (used in both languages)

usually prefixed with a colon (:) in SQL

Page 22: Chapter09

Chapter 9-22Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Example: Variable Declarationin Language C

Variables inside DECLARE are shared and can appear (while prefixed by a colon) in SQL statements

SQLCODE is used to communicate errors/exceptions between the database and the program

int loop;

EXEC SQL BEGIN DECLARE SECTION;

varchar dname[16], fname[16], …;

char ssn[10], bdate[11], …;

int dno, dnumber, SQLCODE, …;

EXEC SQL END DECLARE SECTION;

Page 23: Chapter09

Chapter 9-23Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

SQL Commands forConnecting to a Database

Connection (multiple connections are possible but only one is active)CONNECT TO server-name AS connection-nameAUTHORIZATION user-account-info;

Change from an active connection to another oneSET CONNECTION connection-name;

DisconnectionDISCONNECT connection-name;

Page 24: Chapter09

Chapter 9-24Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Embedded SQL in CProgramming Examples

loop = 1;while (loop) {

prompt (“Enter SSN: “, ssn);EXEC SQL

select FNAME, LNAME, ADDRESS, SALARYinto :fname, :lname, :address, :salaryfrom EMPLOYEE where SSN == :ssn;if (SQLCODE == 0) printf(fname, …);else printf(“SSN does not exist: “, ssn);prompt(“More SSN? (1=yes, 0=no): “, loop);

END-EXEC}

Page 25: Chapter09

Chapter 9-25Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Embedded SQL in CProgramming Examples

A cursor (iterator) is needed to process multiple tuples

FETCH commands move the cursor to the next tuple

CLOSE CURSOR indicates that the processing of query results has been completed

See Fig. 9.4

Page 26: Chapter09

Chapter 9-26Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Dynamic SQL

Objective: executing new (not previously compiled) SQL statements at run-time– a program accepts SQL statements from the

keyboard at run-time– a point-and-click operation translates to certain SQL

query

Dynamic update is relatively simple; dynamic query can be complex – because the type and number of retrieved attributes

are unknown at compile time

Page 27: Chapter09

Chapter 9-27Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Dynamic SQL: An Example

EXEC SQL BEGIN DECLARE SECTION;varchar sqlupdatestring[256];EXEC SQL END DECLARE SECTION;…prompt (“Enter update command:“, sqlupdatestring);EXEC SQL PREPARE sqlcommand FROM :sqlupdatestring;EXEC SQL EXECUTE sqlcommand;

Page 28: Chapter09

Chapter 9-28Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Embedded SQL in Java

SQLJ: a standard for embedding SQL in Java

An SQLJ translator converts SQL statements into Java (to be executed thru the JDBC interface)

Certain classes, e.g., java.sql have to be imported

Page 29: Chapter09

Chapter 9-29Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Java Database Connectivity

JDBC: SQL connection function calls for Java programming

A Java program with JDBC functions can access any relational DBMS that has a JDBC driver

JDBC allows a program to connect to several databases (known as data sources)

Page 30: Chapter09

Chapter 9-30Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Steps in JDBC Database Access

See Section 9.4.4. page 271-275

1. Import JDBC library (java.sql.*)2. Load JDBC driver:

Class.forname(“oracle.jdbc.driver.OracleDriver”)

3. Define appropriate variables4. Create a connect object (via getConnection)5. Create a statement object from the Statement

class:1. PreparedStatment2. CallableStatement

Page 31: Chapter09

Chapter 9-31Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Steps in JDBC Database Access(continued)

6. Identify statement parameters (to be designated by question marks)

7. Bound parameters to program variables8. Execute SQL statement (referenced by

an object) via JDBC’s executeQuery

9. Process query results (returned in an object of type ResultSet)– ResultSet is a 2-dimentional table

Page 32: Chapter09

Chapter 9-32Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Embedded SQL in Java:An Example (1/2)

import java.sql.*;import java.io.*;import sqlj.runtime.*;import sqlj.runtime.ref.*;import oracle.sqlj.runtime.*;…DefaultContext cntxt = oracle.getConnection(“<url

name>”, “<user name>”, “<password>”, true);DefaultContext.setDefaultContext(cntxt);…string dname, ssn, fname, fn, lname, ln, bdate,

address;char sex, minit, mi;double salary, sal;integer dno, dnumber;

Page 33: Chapter09

Chapter 9-33Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Embedded SQL in Java:An Example (2/2)

ssn = readEntry(“Enter a SSN: “);

try {

#sql{select FNAME, LNAME, ADDRESS, SALARY

into :fname, :lname, :address, :salary

from EMPLOYEE where SSN = :ssn};

}

catch (SQLException se) {

System.out.println(“SSN does not exist: “,+ssn);

return;

}

System.out.println(fname+“ “+lname+… );

Page 34: Chapter09

Chapter 9-34Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Multiple Tuples in SQLJSQLJ supports two types of iterators:

– named iterator: associated with a query result– positional iterator: lists only attribute types in a

query resultA FETCH operation retrieves the next tuple

in a query result:fetch iterator-variable into program-variable

See Fig. 9.9 and 9.10, compare them with Fig. 9.4

Page 35: Chapter09

Chapter 9-35Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Database Programming with Functional Calls

Embedded SQL provides static database programming

API: dynamic database programming with a library of functions– advantage: no preprocessor needed (thus

more flexible)– drawback: SQL syntax checks to be done at

run-time

Page 36: Chapter09

Chapter 9-36Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

SQL Call Level Interface

A part of the SQL standardProvides easy access to several

databases within the same programCertain libraries (e.g., sqlcli.h for C)

have to be installed and availableSQL statements are dynamically created

and passed as string parameters in the calls

Page 37: Chapter09

Chapter 9-37Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Components of SQL/CLI

Environment record: keeps track of database connections

Connection record: keep tracks of info needed for a particular connection

Statement record: keeps track of info needed for one SQL statement

Description record: keeps track of tuples

Page 38: Chapter09

Chapter 9-38Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Steps in C and SQL/CLI Programming

1. Load SQL/CLI libraries 2. Declare record handle variables for the

above components (called: SQLHSTMT, SQLHDBC, SQLHENV, SQLHDEC)

3. Set up an environment record using SQLAllocHandle

4. Set up a connection record using SQLAllocHandle

5. Set up a statement record using SQLAllocHandle

Page 39: Chapter09

Chapter 9-39Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Steps in C and SQL/CLI Programming (continued)

6. Prepare a statement using SQL/CLI function SQLPrepare

7. Bound parameters to program variables8. Execute SQL statement via SQLExecute9. Bound columns in a query to a C

variable via SQLBindCol10.Use SQLFetch to retrieve column values

into C variables

Page 40: Chapter09

Chapter 9-40Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

More Examples on SQL/CLI and JDBC

See Section 9.5, page 275-283See Figure 9.11-9.14

Page 41: Chapter09

Chapter 9-41Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

DB Programming in Perl (1)

Install Perl: http://www.activestate.com/Install modules of DBI, DBD:ODBC:

– ppm install DBI– ppm install DBD-ODBC

Set DSN (Data Source Name) –控制台 =>系統管理工具 =>資料來源

(ODBC)=>系統資料來源名稱– E.g., set a DSN=NSC_PatentDB for the file

NSC_PatentDB.mdb.

Page 42: Chapter09

Chapter 9-42Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

DB Programming in Perl (2)sub Insert_into_DSN2_from_DSN1 { my($dsn1, $dsn2) = @_; my($DBH1, $sql1, $STH1, $DBH, $sql, $STH); use DBI; # connect to the $dsn1 for reading $DBH1 = DBI->connect( "DBI:ODBC:$dsn1",,, {

RaiseError => 1, AutoCommit => 0 }) or die "Can't connect database : $DBI::errstr\n"; $DBH1->{LongReadLen}=1280000; # only work for SELECT, not for INSERT $DBH1->{LongTruncOk} = 1;

$sql1 = "SELECT TDescription.PatentNo, TypeNo, Title, Abstract FROM TDescription, TPatentInfo where TDescription.PatentNo = TPatentInfo.PatentNo

order by TDescription.PatentNo, TypeNo";

$STH1 = $DBH1->prepare($sql1) or die "Can't prepare SQL statement: SQL=$sql, $DBI::errstr\n"; $STH1->execute() or die "Can't run SQL statement: SQL=$sql, $STH::errstr\n";

Page 43: Chapter09

Chapter 9-43Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

DB Programming in Perl (3)# connect to the $dsn2 for writing $DBH = DBI->connect( "DBI:ODBC:$dsn2",,, { RaiseError => 1, AutoCommit

=> 0 }) or die "Can't connect database : $DBI::errstr\n"; $sql = qq{ INSERT INTO Seg_Abs6 (Sno, DName, [Desc]) values (?, ?, ?) }; $STH = $DBH->prepare($sql) or die "Can't prepare SQL statement: SQL=$sql, $DBI::errstr\n"; $STH->bind_param(3, $STH, DBI::SQL_LONGVARCHAR);

while (($pid, $TypeNo, $Title, $Abs) = $STH1->fetchrow_array) { next if $TypeNo > 5; $Abs =~ s/<BR><BR>/\n/g; $Abstract .= $Abs . "\n\n"; if ($TypeNo == 5) {

$STH->execute($pid, $Title, $Abstract) or die "Can't run SQL statement: SQL=$sql, $STH::errstr\n";

$Abstract = ""; }

} $STH1->finish; $DBH1->disconnect; $STH->finish; $DBH->disconnect;}

Page 44: Chapter09

Chapter 9-44Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

DB Programming in Perl (4)Print “Enter the department name:”; $dname = <STDIN>;use DBI; $DBH = DBI->connect( "DBI:ODBC:$dsn1",,, { RaiseError => 1, AutoCommit => 0 }) or die "Can't connect database : $DBI::errstr\n";$sql = "SELECT dnumber FROM department WHERE dname = ?";$STH = $DBH->prepare($sql) or die "SQL=$sql, $DBI::errstr\n";$STH->execute($dname) or die "SQL=$sql, $STH::errstr\n";($dno) = $STH->fetchrow_array;print “Employee information for Department: $dname”;$sql = "SELECT ssn,lname, salary FROM employee WHERE dno = ?";$STH = $DBH->prepare($sql) or die "SQL=$sql, $DBI::errstr\n";$STH->execute($dno) or die "SQL=$sql, $STH::errstr\n";while (($ssn, $lname, $salary) = $STH->fetchrow_array) { print “ssn=$ssn, LastName=$lname, Salary=$salary\n”;} $STH->finish; $DBH->disconnect;

Page 45: Chapter09

Chapter 9-45Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Database Stored Procedures

Persistent procedures/functions (modules) are stored locally and executed by the database server (as opposed to execution by clients)

Advantages:– if the procedure is needed by many applications, it

can be invoked by any of them (thus reduce duplications)

– execution by the server reduces communication costs

– enhance the modeling power of views

Page 46: Chapter09

Chapter 9-46Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Stored Procedure Constructs

A stored procedureCREATE PROCEDURE procedure-name (params)

local-declarations

procedure-body;

A stored functionCREATE FUNCTION fun-name (params) RETRUNS return-type

local-declarations

function-body;

Calling a procedure or functionCALL procedure-name/fun-name (arguments);

Page 47: Chapter09

Chapter 9-47Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

SQL Persistent Stored Modules

SQL/PSM: part of the SQL standard for writing persistent stored modules

SQL + stored procedures/functions + additional programming constructs– e.g., branching and looping statements– enhance the power of SQL

Page 48: Chapter09

Chapter 9-48Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

SQL/PSM: An Example

CREATE FUNCTION DEPT_SIZE (IN deptno INTEGER)

RETURNS VARCHAR[7]

DECLARE TOT_EMPS INTEGER;

SELECT COUNT (*) INTO TOT_EMPS

FROM SELECT EMPLOYEE WHERE DNO = deptno;

IF TOT_EMPS > 100 THEN RETURN “HUGE”

ELSEIF TOT_EMPS > 50 THEN RETURN “LARGE”

ELSEIF TOT_EMPS > 30 THEN RETURN “MEDIUM”

ELSE RETURN “SMALL”

ENDIF;

Page 49: Chapter09

Chapter 9-49Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Summary

Assertions provide a means to specify additional constraints

Triggers are a special kind of assertions; they define actions to be taken when certain conditions occur

Views are a convenient means for creating temporary (virtual) tables

Page 50: Chapter09

Chapter 9-50Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Summary (continued)

A database may be accessed via an interactive database

Most often, however, data in a database is manipulate via application programs

Several methods of database programming:– embedded SQL– dynamic SQL– stored procedure and function

Page 51: Chapter09

Chapter 9-51Copyright © 2004 Ramez Elmasri and Shamkant Navathe

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Home Work

Write a small Web-based DBMS application (such as the courses_students) that allows selecting a table and then – Inserting a record– Updating a record– Deleting a record– Selecting records based on some constraints

Using PHP, Perl, and Java, respectively.