6.2 Exercise
Based on logical design of purchase order application that you built in Chapter 5 exercise, you are required to develop a schema level model physical design by writing
DDL statement using SQL3 syntax.
45
6.3 Self Review Questions
1. List object-oriented features of SQL3.
2. Describe user-defined classification in SQL3.
3. What is the difference between row types and ADT Abstract data type?
4. Can column types be used as row types?
5. Can row types be used as column types?
46
7 Introduction
In Oracle 9i, object types represents row types and column types, in which SQL3 makes some distinction for both types. However, the scope of object types usage will
determine whether it is a row object or column object. If object type appears in the whole sequence of object table, it is called as row objects, but if it only occupy some
columns of other object table, it is called column object. Types in Oracle 9i can be divided into several parts as shown in Figure 7-1.
Figure 7-1: Oracle 9i Type classification The objectives of this practical include:
To map object-relational data model on physical design To write DDL statement using Oracle 9i syntax based on object relational
schema
ORACLE 9i TYPES
OBJECT TYPES
REF TYPES COLLECTION
TYPES
ARRAY TYPES
NESTED TABLE
TYPES
47
7.1 Theoretical Background
Here are some examples of Oracle 9i types DDL statement, which are mapped from object-relational data model.
7.1.1 Object type as column type
Type NAME_OBJTYP
firstName midName
lastName VARCHAR215
VARCHAR215 VARCHAR215
CREATE TYPE name_objtyp AS OBJECT firstName VARCHAR215,
midName VARCHAR215, lastName VARCHAR215;
Type ADDRESS_OBJTYP
street City
state poscode
VARCHAR215 VARCHAR210
VARCHAR210 NUMBER
CREATE TYPE address_objtyp AS OBJECT street VARCHAR215,
city VARCHAR210, state VARCHAR210,
poscode number;
48
7.1.2 Object type as row type Type CUSTOMER_OBJTYP
custNo custName
CustAdd ress
VARCHAR215 Name_objtyp
Address _objtyp
CREATE TYPE customer_objtyp AS OBJECT CustNo VARCHAR215,
CustName name_objtyp, CustAddress address_objtyp;
CREATE TABLE customer_tab of customer_objtyp CustNo PRIMARY KEY OBJECT IDENTIFIER PRIMARY KEY;
7.1.3 Collection types - Array type
Type PHONELIST_VARTYP PhoneNum
Maximum 5 values VARCHAR215
CREATE TYPE phonelist_vartyp AS VARRAY 5 OF VARCHAR220;
Modification needs to be made for CUSTOMER_OBJTYP to include the new array type.
Type CUSTOMER_OBJTYP custNo
custName CustAddress
custContact VARCHAR215 Name_objtyp Address_objtyp Phonelist_vartyp
CREATE TYPE customer_objtyp AS OBJECT CustNo VARCHAR215,
CustName name_objtyp, CustAddress address_objtyp,
CustContact Phonelist_vartyp;
CREATE TABLE customer_tab of customer_objtyp CustNo PRIMARY KEY OBJECT IDENTIFIER PRIMARY KEY;
49
Inserting values into customer_tab
Example :
INSERT INTO customer_tab VALUES‘C001’, name_objtyp‘Mohd’,’Azmi’,’Ali’,
address_objtyp‘Jln Merbau’,’Ayer Keroh’,’Melaka’,75450, Phonelist_vartyp‘012-8792345’,’06-5645345’;
7.1.4 Collection types – Nested table
Type DEPENDANT_OBJTYP DependantId PK
dependantName dependantAddress
String Object Type
Object Type VARCHAR210
NAME_OBJTYP ADDRESS_OBJTYP
CREATE TYPE dependant_objtyp AS OBJECT dependantId VARCHAR210,
dependantName name_objtyp, dependantAddress address_objtyp;
Column dependantList of DEPENDANT_NESTEDTAB as table of DEPENDANT_OBJTYP
dependantId dependantName
dependantAddress VARCHAR210
NAME_OBJTYP ADDRESS_OBJTYP
CREATE TYPE dependant_nestedtab AS TABLE OF dependant_objtyp;
Type EMPLOYEE_OBJTYP
EmployeeId PK startDate
dependantList String
Date Nested Table
VARCHAR210 DATE
DEPENDANT_NESTEDTAB
CREATE TYPE employee_objtyp AS OBJECT EmployeeId VARCHAR210,
StartDate DATE, DependantList DEPENDANT_NESTEDTAB;
50
Then, create object table based on object type created for employee.
CREATE TABLE employee_tab of employee_objtyp EmployeeId PRIMARY KEY
OBJECT IDENTIFIER PRIMARY KEY NESTED TABLE DependantList STORE AS DependantListStorageTable
PRIMARY KEY NESTED_TABLE_ID,dependantId ;
OR
CREATE TABLE employee_tab of employee_objtyp PRIMARY KEY EmployeeId
OBJECT IDENTIFIER is PRIMARY KEY NESTED TABLE DependantList STORE AS DependantListStorageTable
PRIMARY KEY NESTED_TABLE_ID, dependantId ;
Inserting values into employee_tab
INSERT INTO employee_tab VALUES E001,SYSDATE,DEPENDANT_NESTEDTAB;
The values for nested table in the DependantList column need to be inserted.
INSERT INTO TABLE SELECT e.dependantList
FROM employee_tab e WHERE e.employeeId = ’E001’
VALUES ‘D101’, name_objtyp‘Nur’,’Ainun’,’Anas’,
address_objtyp‘Jln 120’,’Jasin’,’Melaka’,75450;
51
7.1.5 REF type
REF type is used to show associationrelationship between objects.
Type SYSTEM_OBJTYP
SName PK minAge
VARCHAR215 INTEGER
CREATE TYPE system_objtyp AS OBJECT sname VARCHAR215,
minAge INTEGER ;
Then, create an object table for System.
CREATE TABLE system_tab OF system_objtyp sname PRIMARY KEY
OBJECT IDENTIFIER PRIMARY KEY;
Type SERIES_OBJTYP SrsName PK
theme inSys
VARCHAR215 INTEGER
system_objtyp
CREATE TYPE series_objtyp AS OBJECT srsname VARCHAR215,
theme INTEGER, inSys REF system_objtyp ;
Then, create an object table for Series.
CREATE TABLE series_tab OF series_objtyp PRIMARY KEY srsname,
FOREIGN KEY inSys REFERENCES system_tab OBJECT IDENTIFIER IS PRIMARY KEY;
52
Inserting values into system_tab
Values for values need to be inserted prior to insertion of child table.
INSERT INTO system_tab VALUES‘UNIX’,4;
Then, insert values for child table.
INSERT INTO series_tab SELECT ‘VS400’,1200,REFs
FROM system_tab s WHERE s.sname=’UNIX’;
OR
INSERT INTO series_tab VALUES ‘VS400’,1200, SELECT REFs FROM system_tab s
WHERE s.sname=’UNIX’;
SCOPE FOR constraint on a REF is not allowed in CREATE TABLE statement. Therefore, to ensure that inSys attribute in series_tab table can reference only
object table system_tab, issue the following ALTER TABLE statement on series_tab table.
ALTER TABLE series_tab ADDSCOPE FORinSys IS system_tab;
53
7.1.6 Type inheritance
Oracle 9i allows type inheritance as what is provided by SQL3. With this facility, a subtype can be created under a base type only if the base type allows subtypes. This is
based on FINAL property of type. By default, all new types are created as FINAL. FINAL clause indicates that particular type is the last of the series and cannot have
subtypes defined under it. To enable subtype creation, one must specify NOT FINAL clause in CREATE TYPE statement.
Example :
CREATE TYPE person_ObjTyp AS OBJECT Name VARCHAR230,
Contact VARCHAR29 NOT FINAL; CREATE TYPE student_ObjTyp UNDER person_ObjTyp
StudentId VARCHAR230 NOT FINAL;
CREATE TABLE PERSON OF person_ObjTyp name PRIMARY KEY
OBJECT IDENTIFIER IS PRIMARY KEY;
Inserting values into person
INSERT INTO person VALUES StudentTyp‘Maria Ibrahim’,’06-356788’,’s001’;
7.2 Exercise
54
You have created a schema level model for purchase order application using SQL3 syntax in the previous chapter. Now build a schema level model for the same
application using Oracle syntax.
7.3 Self Review Questions
55
1. Define type classification in Oracle9i.
2. Give an example where object types can be used as row types.
3. Give an example where object types can be used as column types.
4. What is the function of REF type?
5. What do you understand about Nested table type?
56
8 Introduction
The design for distributed database applies all relational database concepts accept that it introduces some additional aspects that need to be considered. Theoretically, a
distributed database stores a logically related database over multiple physically independent sites, which are connected through a computer network. Database
fragments are the building block of distributed database system. In other words, distributed database consists of several small parts called as fragments. The database
fragments are located at different sites, and can also be replicated among various sites.
The objectives of this practical include:
To evaluate and to choose a suitable database system centralized or distributed based on the given requirements
To select and apply data fragmentation strategy. To explore data replication and to decide which fragments to replicate
To choose the right location of the fragments
57
8.1 Theoretical Background