Download MIS 301- Database

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Microsoft Jet Database Engine wikipedia , lookup

Database wikipedia , lookup

Oracle Database wikipedia , lookup

Clusterpoint wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Database model wikipedia , lookup

Open Database Connectivity wikipedia , lookup

SQL wikipedia , lookup

Relational model wikipedia , lookup

PL/SQL wikipedia , lookup

Transcript
MIS 385/MBA 664
Systems Implementation with DBMS/
Database Management
Dave Salisbury
[email protected] (email)
http://www.davesalisbury.com/ (web site)
Routines and Triggers

Routines




Triggers


Program modules that execute on demand
Functions – routines that return values and take
input parameters
Procedures – routines that do not return values
and can take input or output parameters
Routines that execute in response to a database
event (INSERT, UPDATE, or DELETE)
PL/SQL

SQL programming language
Oracle Triggers



Triggers are procedures associated with a
table
Fire upon meeting of trigger condition
Used in Oracle Server to react to specific
situations



enforcing data integrity rules
deriving specific values
Simple example of a trigger might be the
autonum datatype in Access
One Sample Trigger for Class

This sample will store the following
fields in a table (customer history) on
the occurrence of the event (deletion of
a customer (NOTE: need to create the
tables first).



Customer Last Name
First Name
Customer ID
The Code for Customer History
CREATE OR REPLACE TRIGGER DeleteCustomer
BEFORE DELETE ON Customer
FOR EACH ROW
BEGIN
INSERT INTO CustomerHistory
VALUES(:Old.CUSTOMERID, :Old.LastName,
:Old.FirstName);
END DeleteCustomer;
Another Class Sample Trigger
(To display system time)
--PL/SQL program to display the current date
--First set output on
SET SERVEROUTPUT ON;
--Next do the procedure
DECLARE
TodaysDate DATE;
BEGIN
TodaysDate := SYSDATE;
DBMS_OUTPUT.PUT_LINE( 'Todays date is ');
DBMS_OUTPUT.PUT_LINE( TodaysDate);
END;
/
The one from the Book
First define the ORDERID_SEQUENCE
CREATE SEQUENCE
ORDERID_SEQUENCE
START WITH 1012
NOMAXVALUE
NOCACHE;
Now do the Trigger
CREATE TRIGGER ORDER_ID_BIR
BEFORE INSERT ON ORDER_T
FOR EACH ROW
BEGIN
SELECT ORDERID_SEQUENCE.NEXTVAL
INTO :NEW.ORDER_ID
FROM DUAL;
END ORDER_ID_BIR;