Вы находитесь на странице: 1из 8

A P P E N D I X

About the CD-ROM

his CD-ROM contains the following items:

3 Several scripts to create the sample Schemas used in the book. 3 A complete electronic copy of Oracle8 Bible in PDF format. 3 A directory of sample scripts and programs shown throughout the book. 3 Acrobat Reader for easy access to the PDF files.

Sample Tables and Objects


The CD-ROM contains scripts that create and populate the primary Tables and Objects used for examples and stepby-step instructions in the book. You can install the sample Tables into your own Oracle8 database. Three new users are created: SEAPARK, HAROLD, and AMYC. SEAPARK owns the sample relational Tables. AMYC owns the Object types and Object Tables. HAROLD is used for examples involving multiple Users, such as Roles.

Add relational Tables to your database


Follow these steps to install the users SEAPARK and HAROLD and the relational Tables in the AMY Schema. 1. Log in to SQL Worksheet as SYSTEM. The default password is MANAGER. 2. Open the maketables.sql script on the CD-ROM. The script is found in the Make directory.

1080

Appendix B 3 About the CD-ROM

3. Press the Execute button. In the following order, the script creates the Users, the Tables, and finally populates the Tables with data. 4. Close the SQL Worksheet. You now have a User in your database named SEAPARK with a password of SEAPARK that owns a set of relational Tables with all of this books example Columns and data. The following script creates all relational Tables for the SEAPARK Schema.
/* ------------- TANK ----------------------------- */ CREATE TABLE SEAPARK.tank (TANK_NO NUMBER(10,0), chief_caretaker_name VARCHAR2(30) NULL, tank_name VARCHAR2(30) NULL, capacity_gallons NUMBER(10,2) NULL, opening_date DATE NULL, closing_date DATE NULL, CONSTRAINT tank_pk PRIMARY KEY (tank_no)) / /* --------- CHECKUP ------------------------------ */ CREATE TABLE SEAPARK.checkup (checkup_type VARCHAR2(10) NULL, measure_weight_flag CHAR(1) NULL, CHECK_EYES_FLAG CHAR(1) NULL, BLOOD_TEST_FLAG CHAR(1) NULL, CONSTRAINT checkup_pk PRIMARY KEY (checkup_type)) ; /* ------------ CHECKUP_HISTORY --------------------- */ CREATE TABLE SEAPARK.CHECKUP_HISTORY (CHECKUP_NO NUMBER(10,0) NOT NULL, ID_NO NUMBER(10,0), CHECKUP_TYPE VARCHAR2(30), CHECKUP_DATE DATE, DOCTOR_NAME VARCHAR2(50), FOREIGN KEY (CHECKUP_TYPE) REFERENCES SEAPARK.CHECKUP (CHECKUP_TYPE), PRIMARY KEY (CHECKUP_NO)) PCTFREE 20 PCTUSED 60 INITRANS 2 MAXTRANS 255 STORAGE ( INITIAL 1250K NEXT 2K MINEXTENTS 1 MAXEXTENTS 121 PCTINCREASE 0) / /* ------------------- PARK_REVENUE ---------------- */ CREATE TABLE SEAPARK.park_revenue (account_no NUMBER(10,0) NULL, TOTAL_CREDIT NUMBER(10,5) NULL,

Appendix B 3 Sample Tables and Objects

1081

TOTAL_DEBIT NUMBER(10,5)) / /* --------- AQUATIC_ANIMAL -------------------------- */ CREATE TABLE SEAPARK.aquatic_animal (id_no NUMBER(10,0), TANK_NO NUMBER(10,0), animal_name VARCHAR2(30) NULL, birth_date DATE NULL, death_date DATE NULL, CONSTRAINT aq_animal_pk PRIMARY KEY (id_no)) / ALTER TABLE SEAPARK.AQUATIC_ANIMAL ADD( CONSTRAINT AQ_NM_TANK_FK FOREIGN KEY (TANK_NO) REFERENCES SEAPARK.TANK(TANK_NO)) / /* ----------- CARETAKER -------------------------- */ CREATE TABLE SEAPARK.CARETAKER (CARETAKER_NAME VARCHAR2(30), FULL_NAME VARCHAR2(50), CONSTRAINT CARETAKER_PK PRIMARY KEY (CARETAKER_NAME)) / /* -------------- CHECKUP_SEQ ---------------------- */ CREATE SEQUENCE SEAPARK.CHECKUP_SEQ INCREMENT BY 1 START WITH 1 NOMAXVALUE MINVALUE 1 NOCYCLE CACHE 20 NOORDER /

Add Object types and Object Tables to your database


Follow these steps to install the User AMYC and the Object types and Object Tables in the AMYC schema. 1. Log in to SQL Worksheet as SYSTEM. The default password is MANAGER. 2. Open the script on the CD called makeobjects.sql. The script is found in the Make directory. 3. Press the Execute button. In the following order, the script creates the User, the Object types and Object Tables, and finally populates the Object Tables with data. 4. Close the SQL Worksheet. You now have a User in your database named AMYC with a password of AMYC123 that owns a set of Object-oriented Tables with all of this books example Columns and data. A listing of the script follows:

1082

Appendix B 3 About the CD-ROM

-- CREATE OBJECTS AND TYPES AND OBJECT TABLES, NESTED TABLES . --/* -------------------------- Object Type PERSON_T initial partial definition */ CREATE TYPE PERSON_T; /* ------------------------ Object Type BOOK_T initial partial definition */ CREATE TYPE BOOKS_T; /* ----------------------------- Object Type NAME_T */ CREATE TYPE NAME_T AS OBJECT( FIRST_NAME VARCHAR2(25), LAST_NAME VARCHAR2(25)); /* --------------------------- Object Type ADDRESS_T */ CREATE TYPE ADDRESS_T AS OBJECT( STREET VARCHAR2(50), CITY VARCHAR2(25), STATE VARCHAR2(2) , ZIP NUMBER); /* --------------------- Object Type BOOK_LOANED_T */ CREATE TYPE BOOK_LOANED_T AS OBJECT (BOOK_ID REF BOOKS_T, LOAN_DATE DATE, FINE NUMBER(5,2) ); /* --------------------- Object Type BOOKS_RESERVED_T */ CREATE TYPE BOOKS_RESERVED_T AS OBJECT (PERSON_ID REF PERSON_T, WAIT_NO INTEGER ); /* ---------------------- Object Type RESERVED_LIST_T varray */ CREATE TYPE RESERVED_LIST_T AS VARRAY(10) OF BOOKS_RESERVED_T; /* ----------------------------- Object Type PHONE_T */ CREATE TYPE PHONE_T AS OBJECT ( PHONE_TYPE VARCHAR2(20), PHONE_NUMBER VARCHAR2(20) ); /* ------------------------- Object Type PHONE_LIST_T varray */ CREATE TYPE PHONE_LIST_T AS VARRAY(10) OF PHONE_T; /* -------------------- Object Type BOOKS_LOAN_LIST_T nested table */ CREATE TYPE BOOKS_LOAN_LIST_T AS TABLE OF BOOK_LOANED_T; /* --------------------- Object Table ADDRESS_TABLE_T

Appendix B 3 Sample Tables and Objects

1083

Object Table used only in Chapter 24 */ CREATE TABLE ADDRESS_TABLE_T OF ADDRESS_T; /* ------------------- Object Table Index IDX_ADDRESS_ZIP CREATE INDEX IDX_ADDRESS_ZIP ON ADDRESS_TABLE_T(ZIP); /* ------------------------- Relational Table STUDENT Table used only in Chapter 24 */ CREATE TABLE STUDENT ( STUDENT_ID INTEGER NOT NULL, STUDENT_FIRST_NAME VARCHAR2(25) NULL , STUDENT_LAST_NAME VARCHAR2(25) NULL , STUDENT_ADDRESS ADDRESS_T, CONSTRAINT PK_PERSON_1 PRIMARY KEY (STUDENT_ID) ); /* ---------------------------- Object Type PERSON_T complete definition */ CREATE OR REPLACE TYPE PERSON_T AS OBJECT ( PERSON_ID INTEGER, PERSON_NAME NAME_T, PERSON_ADDRESS ADDRESS_T, PERSON_PHONE PHONE_LIST_T, PERSON_BK_LOANED BOOKS_LOAN_LIST_T, PERSON_BL_STATUS CHAR ); /* --------------------- Object Table PERSON_TABLE_T */ CREATE TABLE PERSON_TABLE_T OF PERSON_T (PRIMARY KEY(PERSON_ID)) NESTED TABLE PERSON_BK_LOANED STORE AS BOOK_LOANS_TABLE; /* ------------------------- Object Type BOOKS_T complete definition */ CREATE OR REPLACE TYPE BOOKS_T AS OBJECT ( BOOK_ID INTEGER, BOOK_PUBLISHER VARCHAR2(50), BOOK_AUTHOR_NAME NAME_T, BOOK_TITLE VARCHAR2(100), BOOK_SUBJECT VARCHAR2(50), BOOK_RESERVED_LIST RESERVED_LIST_T ); /* ----------------------- Object Table BOOK_TABLE_T */ CREATE TABLE BOOK_TABLE_T OF BOOKS_T (PRIMARY KEY(BOOK_ID)); /* -------------- Data for Object Tables ---------------- */ INSERT INTO BOOK_TABLE_T VALUES (1,IDG, NAME_t(Amy, Chandi),

1084

Appendix B 3 About the CD-ROM

Rough Guide to Vancouver, Travel, RESERVED_LIST_t() ); INSERT INTO BOOK_TABLE_T VALUES (2,IDG, NAME_t(Iolani, Kalani), Hiking Maui, Travel, RESERVED_LIST_t() ); INSERT INTO BOOK_TABLE_T VALUES (3,SCIFI Press, NAME_t(Isaac, Asimov), Foundation, Science Fiction, RESERVED_LIST_t() ); INSERT INTO BOOK_TABLE_T VALUES (4,SCIFI Press, NAME_t(Isaac, Asimov), Best of Science Fiction, Science Fiction, RESERVED_LIST_t() ); INSERT INTO BOOK_TABLE_T VALUES (5,SCIFI Press, NAME_t(Ray, Bradbury), The Illustrated Man, Science Fiction, RESERVED_LIST_t() ); INSERT INTO BOOK_TABLE_T VALUES (6,Time Life, NAME_t(Joe, Banks), The Technical Drummer, Music, RESERVED_LIST_t() ); INSERT INTO BOOK_TABLE_T VALUES (7,Time Life, NAME_t(Joe, Dieter), Slide Guitar, Music, RESERVED_LIST_t() ); INSERT INTO PERSON_TABLE_t VALUES (1, NAME_t(Tony, Prem), ADDRESS_t(11316 Jollyville,Austin, TX, 78759), PHONE_LIST_T(PHONE_t(Home, 512-555-1212)), BOOKS_LOAN_LIST_T(), Y ); INSERT INTO PERSON_TABLE_t VALUES (2, NAME_t(Amy, Chandi), ADDRESS_t(100 West Main St,Austin, TX, 78759), PHONE_LIST_T(PHONE_t(Home, 522-212-2222)),

Appendix B 3 Example SQL Scripts

1085

BOOKS_LOAN_LIST_T(), Y ); INSERT INTO PERSON_TABLE_t VALUES (3, NAME_t( Cortney, Dumas), ADDRESS_t(215 E Dewey St,Dallas, TX, 78799), PHONE_LIST_T(PHONE_t(Home, 529-112-2322)), BOOKS_LOAN_LIST_T(), Y ); INSERT INTO PERSON_TABLE_t VALUES (4, NAME_t(Patrick, Mohyde), ADDRESS_t(80 Kealani St,Honolulu, HI, 12345), PHONE_LIST_T(PHONE_t(Home, 689-198-7567)), BOOKS_LOAN_LIST_T(), Y ); /* ---- update persons first name ---------------------- */ update person_table_t a set A.PERSON_NAME.FIRST_NAME = Cortney where A.PERSON_NAME.FIRST_NAME = Cortney; /* ---------------- update book table ------------ */ UPDATE BOOK_TABLE_T A SET A = BOOKS_T( 1, IDG, NAME_t(Amy, Chandi), Rough Guide to British Columbia, Travel, RESERVED_LIST_t() ) where a.book_id = 1; /* - sequence for Person_TABLE_t and Book_TABLE_t ------- */ CREATE SEQUENCE ID_SEQ INCREMENT BY 1 START WITH 10 NOMAXVALUE MINVALUE 1 NOCYCLE CACHE 20 NOORDER; /* copyright 1998 Carol McCullough-Dieter */

Example SQL Scripts


Several of the chapters contain SQL scripts you can run after importing the sample database. Table B-1 shows all scripts located on the CD-ROM in the Scripts directory.

1086

Appendix B 3 About the CD-ROM

Table B-1 Sample SQL Scripts in the Scripts Directory


File Description Simple DELETE command to remove rows from a Table Simple INSERT command to add one row to a Table

delete.sql insert.sql insert_subquery.sql join.sql jointhree.sql update.sql update_correlated_ subquery.sql update_subquery.sql update_where.sql all_synonyms.sql break.sql select_count.sql select_variable.sql length.sql rownum.sql rownum_complex.sql rpad.sql

INSERT command to add many rows using a subquery


Join two Tables Join three Tables Simple UPDATE command to modify one Column

UPDATE command using correlated subquery UPDATE selected rows using subquery UPDATE sets of rows using WHERE clause
List all Synonyms Create a report with summary break points in SQL*Plus Count rows in a Table Creating a variable in SQL*Plus Sample of LENGTH function Sample of ROWNUM pseudocolumn Sample of ROWNUM pseudocolumn to limit rows selected Sample of using RPAD function

You can run these scripts if you have installed the sample tables and objects included in the CD-ROM.

Acrobat Reader
If you have Acrobat Reader installed on your computer, you are ready to view the PDF files included on the CD-ROM. If not, the CD-ROM contains the program. Open the Acrobat Reader folder and double-click the setup file to begin installation. Now you have access to any of the information in this book via the CD-ROM!

Вам также может понравиться