Sie sind auf Seite 1von 32

I

Introduction

Objectives
After completing this lesson, you should be After completing this lesson, you should be able to do the following: able to do the following: Discuss the theoretical and physical aspects Discuss the theoretical and physical aspects of a relational database of a relational database Describe the Oracle implementation of the Describe the Oracle implementation of the RDBMS and ORDBMS RDBMS and ORDBMS Describe how SQL and PL/SQL are used in Describe how SQL and PL/SQL are used in the Oracle product set the Oracle product set Describe the use and benefits of PL/SQL Describe the use and benefits of PL/SQL
I-2

System Development Life Cycle


Strategy and Analysis

Design Build and Document Transition Production

I-3

System Development Life Cycle


Strategy and Analysis

Design Build and Document Transition Production

I-4

Data Storage on Different Media


SALGRADE SALGRADE
GRADE LOSAL HISAL GRADE LOSAL HISAL --------- --------- ----------------- --------- --------DEPT DEPT 1 700 1200 1 700 1200 DNAME LOC DNAME LOC 2 1201 1400 1201 1400 -------------- ---------- 2 -------------- ---------3 1401 2000 1401 2000 10 ACCOUNTING NEW3 10 ACCOUNTING NEW 4 2001 3000 4 2001 3000 5 3001 9999 5 3001 9999 RESEARCH DALLAS RESEARCH DALLAS SALES CHICAGO SALES CHICAGO OPERATIONS BOSTON OPERATIONS BOSTON DEPTNO DEPTNO ----------------YORK YORK 20 20 30 30 40 40

Database Electronic spreadsheet


I-5

Filing cabinet

Relational Database Concept


Dr. E. F. Codd proposed the relational model for Dr. E. F. Codd proposed the relational model for database systems in 1970. database systems in 1970. It is the basis for the relational database It is the basis for the relational database management system (RDBMS). management system (RDBMS). The relational model consists of the following: The relational model consists of the following:
Collection of objects or relations Collection of objects or relations Set of operators to act on the relations Set of operators to act on the relations Data integrity for accuracy and consistency Data integrity for accuracy and consistency

I-6

Relational Database Definition


A relational database is a collection of A relational database is a collection of relations or two-dimensional tables. relations or two-dimensional tables.
Database

Table Name: EMP


EMPNO EMPNO 7839 7839 7698 7698 7782 7782 7566 7566 ENAME ENAME KING KING BLAKE BLAKE CLARK CLARK JONES JONES JOB JOB PRESIDENT PRESIDENT MANAGER MANAGER MANAGER MANAGER MANAGER MANAGER DEPTNO DEPTNO 10 10 30 30 10 10 20 20

Table Name: DEPT


DEPTNO DEPTNO 10 10 20 20 30 30 40 40 DNAME DNAME ACCOUNTING ACCOUNTING RESEARCH RESEARCH SALES SALES OPERATIONS OPERATIONS LOC LOC NEW YORK NEW YORK DALLAS DALLAS CHICAGO CHICAGO BOSTON BOSTON

I-7

Data Models

Model of system in clients mind

Entity model of clients model Table model of entity model

Server

Tables on disk
I-8

Entity Relationship Model


Create an entity relationship diagram from Create an entity relationship diagram from business specifications or narratives business specifications or narratives
EMPLOYEE EMPLOYEE #* number #* number * name * name o job title o job title DEPARTMENT DEPARTMENT #* number #* number * name * name composed of composed of o location o location

assigned to assigned to

Scenario Scenario . .. .. Assign one or more employees to a . Assign one or more employees to a department .. .. . department . . .. .. Some departments do not yet have . Some departments do not yet have assigned employees .. .. . assigned employees .
I-9

Entity Relationship Modeling Conventions


Entity Soft box Singular, unique name Uppercase Synonym in parentheses Attribute Singular name Lowercase Mandatory marked with * Optional marked with o

EMPLOYEE EMPLOYEE #* number #* number * name * name o job title o job title

assigned to assigned to

DEPARTMENT DEPARTMENT #* number #* number * name name composed of * composed of o location o location

Unique Identifier (UID) Primary marked with # Secondary marked with (#)
I-10

Entity Relationship Modeling Conventions


Entity Soft box Singular, unique name Uppercase Synonym in parentheses Attribute Singular name Lowercase Mandatory marked with * Optional marked with o

EMPLOYEE EMPLOYEE #* number #* number * name * name o job title o job title

assigned to assigned to

DEPARTMENT DEPARTMENT #* number #* number * name name composed of * composed of o location o location

Unique Identifier (UID) Primary marked with # Secondary marked with (#)
I-11

Relational Database Terminology


2
EMPNO ENAME -----------------------JOB

3
MGR HIREDATE SAL --------------------- -------- ---------------- ----------- -------------PRESIDENT MANAGER MANAGER MANAGER SALESMAN SALESMAN 7839 7839 7839 7698 7698 7698 7698 7698 7566 7902 7566 7788 7782 17-NOV-81 01-MAY-81 09-JUN-81 02-APR-81 28-SEP-81 20-FEB-81 08-SEP-81 03-DEC-81 22-FEB-81 03-DEC-81 17-DEC-80 09-DEC-82 12-JAN-83 23-JAN-82 5000 2850 2450 2975 1250 1600 1500 950 1250 3000 800 3000 1100 1300 500 1400 300

4
COMM DEPTNO ----------10 30 10 20 30 30 30 30 30 20 20 20 20 10

7839 KING 7698 BLAKE 7782 CLARK 7566 JONES 7654 MARTIN 7499 ALLEN

7844 TURNER SALESMAN 7900 JAMES 7521 WARD 7902 FORD 7369 7788 7876 SMITH SCOTT ADAMS MILLER CLERK SALESMAN ANALYST CLERK ANALYST CLERK CLERK

1
I-12

7934

Relating Multiple Tables


Each row of data in a table is uniquely Each row of data in a table is uniquely identified by a primary key (PK). identified by a primary key (PK). You can logically relate data from You can logically relate data from multiple tables using foreign keys (FK). multiple tables using foreign keys (FK).
Table Name: EMP
EMPNO 7839 7698 7782 7566 ENAME KING BLAKE CLARK JONES JOB PRESIDENT MANAGER MANAGER MANAGER DEPTNO 10 30 10 20

Table Name: DEPT


DEPTNO 10 20 30 40 DNAME ACCOUNTING RESEARCH SALES OPERATIONS LOC NEW YORK DALLAS CHICAGO BOSTON

Primary key
I-13

Foreign key

Primary key

Relational Database Properties


A relational database A relational database Can be accessed and modified by Can be accessed and modified by executing structured query language executing structured query language (SQL) statements (SQL) statements Contains a collection of tables with no Contains a collection of tables with no physical pointers physical pointers Uses a set of operators Uses a set of operators

I-14

Communicating with a RDBMS Using SQL


SQL statement is entered
SQL> SELECT loc SQL> SELECT loc 22 FROM FROM dept; dept;

Statement is sent to database Database

Data is displayed
LOC LOC ------------------------NEW YORK NEW YORK DALLAS DALLAS CHICAGO CHICAGO BOSTON BOSTON I-15

Relational Database Management System


Server

User tables
I-16

Data dictionary

Oracle8: Object Relational Database Management System


User-defined data types and objects User-defined data types and objects Fully relational compatible Fully relational compatible Support of multimedia and large objects Support of multimedia and large objects High-quality database server features High-quality database server features

I-17

Defining an Object
An object An object Is a person, place, or thing Is a person, place, or thing Knows things about itself and performs Knows things about itself and performs actions actions Has an identity Has an identity

I am a clock. I know my time zone, and I can display time.


I-18

Using an Object Model


Objects model a problem to solve. Objects model a problem to solve. The model is stated in terms of the The model is stated in terms of the interactions between objects. interactions between objects. Object models closely resemble the real Object models closely resemble the real world. world.
Buy Sell

Customers
I-19

Business

Characteristics of Object systems


Present information in object form Present information in object form Classify objects into object types Classify objects into object types Inherit attributes and code Inherit attributes and code Hide data, code, and attributes Hide data, code, and attributes Interact with other objects Interact with other objects Recognize different objects without Recognize different objects without analysis analysis Interpret the same command in Interpret the same command in different ways different ways
I-20

Oracle Complete Solution


Applications Applications HR HR Financials Financials Manufacturing Manufacturing ... ... Developer 2000 Developer 2000 Discoverer Discoverer Designer 2000 Designer 2000

SQL SQL

PL/SQL PL/SQL

SQL* Plus SQL* Plus

Oracle7/8

Database

Data dictionary Data tables

I-21

SQL Statements
SELECT INSERT UPDATE DELETE CREATE ALTER DROP RENAME TRUNCATE COMMIT ROLLBACK SAVEPOINT GRANT REVOKE
I-22

Data retrieval Data manipulation language (DML)

Data definition language (DDL)

Transaction control

Data control language (DCL)

About PL/SQL
PL/SQL is an extension to SQL with PL/SQL is an extension to SQL with design features of programming design features of programming languages. languages. Data manipulation and query statements Data manipulation and query statements of SQL are included within procedural of SQL are included within procedural units of code. units of code.

I-23

PL/SQL Environment
PL/SQL engine PL/SQL block PL/SQL block PL/SQL SQL Procedural Statement Executor

SQL Statement Executor Oracle Server

I-24

Benefits of PL/SQL
Integration Integration

Application

Shared library
I-25

Oracle Server

Benefits of PL/SQL
Improve Performance Improve Performance
SQL

Application Application

SQL SQL SQL

Other DBMSs Other DBMSs

Application Application

SQL IF...THEN SQL ELSE SQL END IF; SQL

Oracle with Oracle with PL/SQL PL/SQL

I-26

Benefits of PL/SQL
Modularize program development Modularize program development
Anonymous Anonymous block block Stored Stored procedure/ procedure/ function function Application Application procedure/ procedure/ function function

DECLARE BEGIN EXCEPTION

Application Application trigger trigger

Database Database trigger trigger

END;

Packaged Packaged procedure procedure

I-27

Benefits of PL/SQL
It is portable. It is portable. You can declare identifiers. You can declare identifiers. You can program with procedural You can program with procedural language control structures. language control structures. It can handle errors. It can handle errors.

I-28

Benefits of PL/SQL
It is portable. It is portable. You can declare identifiers. You can declare identifiers. You can program with procedural You can program with procedural language control structures. language control structures. It can handle errors. It can handle errors.

I-29

EMP

Tables Used in the Course


HIREDATE SAL COMM DEPTNO HIREDATE SAL COMM DEPTNO --------- --------- --------- ----------------- --------- --------- --------17-NOV-81 5000 10 17-NOV-81 5000 10 01-MAY-81 2850 30 01-MAY-81 2850 30 09-JUN-81 1500 10 09-JUN-81 1500 10 02-APR-81 2975 20 02-APR-81 2975 20 28-SEP-81 1250 1400 30 28-SEP-81 1250 1400 30 20-FEB-81 1600 300 30 20-FEB-81 1600 300 30 08-SEP-81 1500 0 30 08-SEP-81 1500 0 30 03-DEC-81 950 30 03-DEC-81 950 30 22-FEB-81 1250 500 30 22-FEB-81 1250 500 30 SALGRADE 03-DEC-81 3000 20 03-DEC-81 3000 20 17-DEC-80 800 20 17-DEC-80 800 20 GRADE LOSAL HISAL GRADE LOSAL HISAL 09-DEC-82 3000 20 09-DEC-82 --------- --------- --------3000 20 --------- --------- --------12-JAN-83 1100 1 20 12-JAN-83 1100 1 20 700 1200 700 1200 23-JAN-82 1300 2 10 23-JAN-82 1300 2 10 1201 1400 1201 1400 3 1401 2000 3 1401 2000 4 2001 3000 4 2001 3000 5 3001 9999 5 3001 9999

EMPNO ENAME JOB MGR EMPNO ENAME JOB MGR --------- ---------- --------- ----------------- ---------- --------- --------7839 KING PRESIDENT 7839 KING PRESIDENT 7698 BLAKE MANAGER 7839 7698 BLAKE MANAGER 7839 7782 CLARK MANAGER 7839 7782 CLARK MANAGER 7839 7566 JONES MANAGER 7839 7566 JONES MANAGER 7839 7654 MARTIN SALESMAN 7698 7654 MARTIN SALESMAN 7698 7499 ALLEN SALESMAN 7698 7499 ALLEN SALESMAN 7698 7844 TURNER SALESMAN 7698 7844 TURNER SALESMAN 7698 DEPT 7900 JAMES CLERK 7698 7900 JAMES CLERK 7698 SALESMAN 7698 7521 SALESMAN 7698 DEPTNO 7521 WARD LOC DEPTNO DNAME WARD DNAME LOC ANALYST 7566 7902 FORD ANALYST 7566 --------- 7902 FORD --------- -------------- ----------------------- ---------7369 10 ACCOUNTING CLERK NEW 7902 7369 SMITH SMITH CLERK NEW 7902 10 ACCOUNTING 7788 SCOTT ANALYST 7566 7788 SCOTT ANALYST 7566 YORK YORK CLERK 7788 7876 ADAMS CLERK 7788 20 7876 ADAMS DALLAS 20 RESEARCH RESEARCH DALLAS 7934 MILLER CLERK 7782 CLERK 7782 30 SALES MILLER CHICAGO 30 7934 SALES CHICAGO 40 OPERATIONS BOSTON 40 OPERATIONS BOSTON

I-30

Summary
Relational databases are composed of Relational databases are composed of relations, managed by relational relations, managed by relational operations, and governed by data operations, and governed by data integrity constraints. integrity constraints. Oracle Server allows you to store and Oracle Server allows you to store and manage information by using the SQL manage information by using the SQL language and PL/SQL engine. language and PL/SQL engine. PL/SQL is an extension to SQL with PL/SQL is an extension to SQL with design features of programming design features of programming languages. languages.
I-31

I-32

Das könnte Ihnen auch gefallen