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

8

,
. ,
. 
, , . 
,
, 
.
UML , 
. , , 
, 
.  , 
. 
, , 
.
. 
, , 
, , 
.
, .. , 
,
.

8.1.


. ,
BCED (. 6.1.3.2) 
, .
 ,
, . 
,

316

8.

.  
(persistent data base layer).

: (, Sybase, DB2, Oracle8), 
 (, UniSQL, Oracle8) (, Ob
jectStore, Versant). , 

(, IMS), (, IDMS), 
(, Total, Adabas). ,
, 
.

8.1.1.

. .
(.. UML 
). 
(
), 
.
(data model) ( (database schema)
, 
, .
.
1. ( ).
2. .
3. .
(external schema)
, . 
, . 
. 
ER
(entityrelationship ) [51].
(logical schema) ( 
) , .

, , .
(physical schema) . 

, , . 
, 
.
CASE (.. ,
)
. 
.

8.1.

317

. 8.1 , UML
. 
 . UML ( 
) ER 
.
, 
. 
, 
.
 .
.
UML&

. 8.1. UML

8.1.2.
,
, (. 6.1.3). 
. ,
 
. ,
.
(.
5.2.4 6.1.3.2)  , 
. , 
.

318

8.


, , .

, ,
. , 
, 
, 
.

. .
, 

( )  .
, ,
, 
.  
. , , 
, , 
.

8.2.
() 
. 
, 
, .
ODMG (Object Data Management Group 
) . ,
ODMG, . ODMG
,
.
API (Object Storage
API), .
, (. 8.1)
. (
2000 ) (Object Data Standard):
ODMG 3.0 [58].
, ()
( SQL) 
. 

. , 
,
, ,
(.. , ) ..
, 
.

8.2.

319

SQL (OSQL). OSQL SQL



, (. 6.2.2.5).

8.2.1.

[58], [20]. (OID) (. 2.1.1.3).
OID .
() ().
. , Employee ()
Smalltalk / Java. 
. 
. 
.
.
(.. , 
).

8.2.1.1.

. 
 . 
,  ,
( 
), , 
.
ODMG 3.0 [58]:
();
;
();
(null).
:

short ( );
long ( );
unsigned short ( );
unsigned long ( );
float (() );
double ( );

char ( );
string ( );
boolean (.. );

320

8.

octet ( );
enum ( ).

, . 
:
(, 9 2001);
(, 11:14);
(, 9 2001 11:14:56);
(, 11:14, 11:19).
 , .. 
(. 6.2.2.5), 
. :
set<t> ( set (),
t; , set<dept_name>, dept_name
string);
bag<t> ( (, ));
list<t> ( () );
array<t> ( ,
,
);
dictionary<t,v> ( ()
, ).
(null)
(, string list<>). .
null 
: (,
) (, , 
).
, , . (
null. . .).
ODMG 3.0 [58]:
;
;
( , ,
, ; , set<Dept>,
Dept ).
. 8.2 . Employee
. (emp_name) . 
emp_name OID PersonName.
PersonName , , , ,
family_name (), first_name () middle_initial ().

8.2.

321

<<ODB>>
Employ ee
emp_id : string
emp_name : PersonName
date_of_birth : date
gender : enum{M,F}
phone_num : array<string>
salary : float

. 8.2.

8.2.1.2.
,
. (.. , 
), . 
.
, 
, (Set<>) (List<>). 
 ,
, . ( 
... , 
modus operandi.)
. 8.3 ,
Student CourseOffering .
.
, (crs_off std)
.
inverse, , 
(referential integrity) 
(dangling pointers) (.. , 
() . . .) , Student 
CourseOffering, CourseOffering (
OID ) Set<CourseOffering>,
Student List<Student>. , 
, () 
.
,
(key) 
.
(
OID). , 
.
(simple) (compound) (
, ).
, , , 
( ).

322

8.

<<ODB>>
Student

<<ODB>>
CourseOffering

<<attribute>> name : string


<<attribute>> stud_id : string
<<relationship>> crs_off : Set<CourseOffering>

<<attribute>> crs_name : string


<<attribute>> semester : string
<<relationship>> std : List<Student>

class Student
{
attribute

string

name;

attribute

string

stud_id;

relationship

Set<CourseOffering>
inverse

crs-off

CourseOffering: :std;

};
class CourseOffering
{
attribute

string

crs_name;

attribute

string

stud_id;

relationship

List<Student>

std

inverse

Student: :crs_off;

};
. 8.3.

8.2.1.3. ISA EXTENDS


ODMG . 
ISA EXTENDS. ISA ( )
(. 5.3.3).
EXTENDS (. 5.3.4). (ISA
, is a , EXTENDS
. , 
, ,
. . .).
. 8.4 UML, ISA
EXTENDS. EmployeeClass
PersonInterface. PersonInterface
. ManagerClass , 
age () EmployeeClass.
ODMG interface 
, PersonInterface. class
, , ,
ManagerClass EmployeeClass.

8.2.

323

<<ODB Class>>
EmployeeClass

<<ODB Interface>>
PersonInterface
ISA

emp_id : string
dob : date
age(in dob)

EXTENDS
<<ODB Class>>
Manager Class
managerial_position : string
salary_supplement : float

. 8.4.

8.2.1.4.
, 
.
, . 
,
.
(
) [58]. 
.
Date
ushort day_of_year()
Month month_of_year()
Weekday day_of_week()
boolean is_leap_year()
boolean is_greater(in Date a_date)
boolean is_between(in Date a_date, in Date b_date)
Date add_days(in long days)
long subtract_date(in Date a_date)
Time
ushort millisecond()
boolean is_equal(in Time a_time)
boolean is_between(in Time a_time, in Time b_time)
Time subtract_interval(in Interval an_interval)

324

8.

Interval subtract_time(in Time a_time)


Timestamp
ushort millisecond()
ushort month()
boolean is_between(in Timestamp a_stamp, in Timestamp b_stamp)
Timestamp plus(in Interval an_interval)
Timestamp minus(in Interval an_Interval)
Interval
ushort second()
Interval plus(in Interval an_interval)
boolean is_less_or_equal(in Interval an_interval)
boolean is_zero()
 .
Collection. 
Collection ( , 
). 
.
unsigned long cardinality()
boolean is_ordered()
boolean contains_element(in any element)
void insert_element(in any element)
void remove_element(in any element) raises(ElementNotFound)
Set
Set create_union(in Set other_set)
boolean is_subset_of(in Set other_set)
boolean is_proper_superset(in Set other_set)
Bag
unsigned long occurrences_of(in any_element)
Bag create_intersection(in Bag other_bag)
List
any retrieve_element_at(in unsigned long index) raises(InvalidIndex)
void insert_element_after(in
raises(InvalidIndex)

any

element,

in

void insert_element_first(in any element)


void remove_last_element() raises(ElementNotFound)
List concat(in List other_list)
void append(in List other_list)

unsigned

long

index)

8.2.

325

Array
void remove_element_at(in unsigned long index) raises(InvalidIndex)
any retrieve_element_at(in unsigned long index) raises(InvalidIndex)
void resize(in unsigned long new_size)
Dictionary
any lookup(in any key) raises(KeyNotFound)
boolean contains_key(in any key)

8.2.2.
UML 
. , 
 . ,

.

, . 
, .
. 
(. 6.1),
(. 6.2) /
(Chapter 9). , 
,
.
/.

8.2.2.1.

UML , ,

(Date, Currency). , 
(), ,
, 
.
: 
? 
? 
? , , , :
,
, , ,
?
?
UML 
( ) ( 
). , ,
, ,

326

8.


, . ,
, ,
.
, 
.
, . 
.

8.1.
4.6, . 4.3 (. 4.2.1.2.3). Contact
Employee. , .
Contact family_name first_name, , (.. ).
Employee family_name, first_name middle_name,
,
.
Contact phone, fax email. ,
.
-
Contact Employee . .

. 8.5. 
PersonShortName ( ) PersonLongName
( ).
contact_name. contact_name
Contact ISA. , ISA 
. Contact
PersonShortName. PersonShortName 
contact_name.
PersonLongName ISA
employee_name.
, ISA Employee PersonLongName
, .
(Contact)
, set
, .

8.2.

<<ODB Interfase>>

<<ODB Class>>

PersonShortName

Contact

family_name : string

<<key>> contact_id : unsigned short

first_name : string

327

ISA

contact_name : PersonShortName
phone : set<string>
fax : set<string>
email : set<string>

<<ISA>>
<<ODB Interfase>>
PersonLongName
middle_initial : char

<<ODB Class>>
Employee

ISA

<<key>> employee_id : string


employee_name : P ersonLongName

. 8.5. 
( )

8.2.2.2.
UML
. ,
, 
.

, , ,
Student CourseOffering . 8.2.1.2 (. 8.3). 
( ), 
.

. , ,
UML ( UML) , 

( . 8.5).

8.2.

4.8, . 4.5 (. 4.2.2.3).
- (. 8.5).
, . 4.5,
. , UML-
. ( ) .

. 8.6. 
 (PersonShortName PersonLongName)
(inheritance hierarchy)  Address.
postal_address courier_address 

328

8.

Organization Contact (nested attribute).


, .
<<ODB Interfase>>
PersonShortName

<<ODB Interfase>>
Address

family_name : string
first_name : string

street : string
city : string
state : string
country : string

ISA
ISA
<<ODB Interfase>>
PersonLongName

<<ODB Interfase>>
PostalAddress

middle_initial : char

po_box : string
post_code : string

ISA

<<ODB Interfase>>
CourierAddress
directions : string

<<ODB Class>>
Organization

<<ODB Class>>
Contact

organization_id : unsigned short


phone : set<string>
fax : set<string>
email : string
is_current : boolean
postal_address : PostalAddress
courier_address : CourierAddress
contact : Set<Contact>
task : Set<Task>

<<key>> contact_id : unsigned short


contact_name : PersonShortName
phone : set<string>
fax : set<string>
email : set<string>
postal_address : PostalAddress
courier_address : CourierAddress
organization : Organization
task : Set<Task>

<<ODB Class>>
Event
description : string
task : Task
created_dt : date
created_emp : Employee
due_dt : date
due_emp : Employee
completed_dt : date
priority : char

<<ODB Class>>
Task
description : string
created_dt : date
value : float
created_emp : Employee
event : List<Event>
organization : Organization
contact : Set<Contact>

<<ODB Class>>
Employee
<<key>> employee_id : string
employee_name : P ersonLongName
created_task : List<Task>
created_event : Set<Event>
due_event : List<Event>
completed_event : Set<Event>

. 8.6. ( )

8.2.

329

8.2.2.3.
(. 2.1.4, 4.2.3 5.4), UML 

. UML
( 
).

. ,
(..
), (
).
. UML
, . UML
, , 
.
(.. ), 
. 
. 
, , 
.. 
.

8.3.

4.9, . 4.6 (. 4.2.3.3).
, . 4.6,
. , - .

. 8.7 . :
YearSemester AcademicRecord.
. UML
academic_record Student.
UML Course CourseOffering
. .
, 
. 4.6.

8.2.2.4.
UML ISA EXTENDS 
. ISA 
.
EXTENDS.
UML . 8.8. 
. 4.7 ,
ISA OMG.

330

8.

UML RentalConditions . 

rental_cond,  VideoMedium. ,
RentalConditions VideoMedium , , 
, VideoMedium
(.. BetaTape, VHSTape DVDDisk).

8.4.

4.10, . 4.7 (. 4.2.4.3).
, . 4.7,
. UML- ( ),
,
.

<<ODB Interfase>>
YearSemester
year : date
semester : unsigned short

<<ODB Class>>
Course
course_code : string
course_name : string
credit_points : unsigned short
course_offering : list<CourseOffering>

<<ODB Class>>
AcademicRecord
course_code : string
year_sem : YearSemester
grade : string

<<ODB Class>>
CourseOffering
year_sem : YearSemester
enrolment_quota : unsigned short
course : Course
student : list<Student>
academic_in_charge : AcademicInCharge

<<ODB Class>>
Student
student_id : string
student_name : string
current_fees : float
course_off : list<CourseOffering>
academic_record : set<AcademicRecord>

<<ODB Class>>
AcademicInCharge
course_off : list<CourseOffering>

. 8.7. ( )

8.3.

<<ODB Interfase>>
RentalConditions

331

<<ODB Interfase>>
VideoMedium

rental_period_in_days : unsigned short


rental_charge_per_period : float

video_condition : char
number_currently_available:unsigned short
rental_cond : RentalConditions
movie_title : MovieTitle

ISA

ISA

<<ODB Class>>
MovieTitle
<<key>> movie_code : string
movie_title : string
director : string
/ is_in_stock : boolean

<<ODB Interfase>>
VideoTape
is_taped_over : boolean

<<ODB Interfase>>
VideoDisk
different_languages : boolean
different_endings : boolean

video_medium : set<VideoMedium>

ISA

<<ODB Class>>
BetaTape

ISA

ISA

<<ODB Class>>
VHSTape

<<ODB Class>>
DVDDisk

. 8.8. ( )

8.3.


 [87]. ,  
() 
.  
() (
) ( ).
1999 ,
( SQL3).

(American National Standards Institute ANSI) 
(International Organization for Standardization ISO). 
SQL:1999 [21]. , , 
.

332

8.


SQL92.
,
SQL . 

(
).
( ), 
(Oracle, IBM, Informix)
, .

, 
, 
. SQL: 1999 .

SQL:1999 [21], , 
( , Oracle 8), 
.

8.3.1.

.
,
UML .
.
.
(. 5.3.3).
. 
, . 
(, Oracle8)
, .
, 
. 
(row type) 
. 
(reference type). .

8.3.1.1.

, . ,
, (. 8.2.1.1).
.
, , :
(distinct type)
, (source type) (
ODMG);

8.3.

333

(structured type)
(
ODMG).

. 
.
, .
, .
, /,
(,
,

).
,
, . SQL:1999
(
):
(set);
(list);
(multiset) (, bag );
(array).
. 8.9 Employee,
, . 8.2.
, 
( , 
). gender () char, ,
, enum. 
, (check constraint) gender (. 8.4).
<<structured type>>
EmployeeTY
emp_id : char(7)
emp_name : PersonName
date_of_birth : date
gender : char
phone_num : set(varchar(12))
salary : money

. 8.9. 


8.3.1.2.
( ) .
, 

334

8.

. (table row) () (.
. 8.3.1.3 ). , 
OID. ,
, .
, ,
TY. 
EmployeeTY 
EmployeeTY. ,
TY. SQL:1999 

create table Employee of EmployeeTY;

SQL:1999
(, . 2.1.2.1.2 5.1.4) [21]. ,
SQL:1999 , 
(observer (get)) (mutator (set)). , , 
.

8.3.1.3.
(row type)

. ( <
>< >).
. .
,
.

(. . 8.6).
create table Contact
(contact_id integer,
contact_name row
(family_name varchar(30),
first_name
varchar(20)),
postal_address row
(po_box varchar(10),
post_code varchar(10),
address row
(street varchar(30),
city varchar(20),
state
varchar(20),
country varchar(25))));


, 

.

8.3.

335

8.3.1.4.
(reference
type). ref. , emp
ref(EmployeeTY) 
. SQL:1999 ,
, (.. 
(. . 2.1.5.2.3)).
, OID, 
; ,
(referenceable table). 
(typed table), .. . 
.
(.
8.3.1.1) . . 8.10 ,
. 8.3, ,
Student CourseOffering.
<<object table>>
Student

<<object table>>
CourseOffering

name : varchar(60)
stud_id : char(8)
crs_off : set(ref(CourseOffering))

crs_name : varchar(40)
semester : char
std : list(ref(Student))

. 8.10. 

8.3.1.5. ,
SQL:1999 ,
[83]. .
.
(column) .
(field) .
(attribute) .
(nullable) NULL.
( OID).
, .

8.3.1.6. OF UNDER
SQL:1999 .
.
, .. (.
of) , . , 
, . 8.11.
SQL:1999, . 8.11, 
(ManagerTY) (Manager).
under SQL:1999
. of .

336

8.

OF 
.
ManagerTY instantiable , 
.
final , .
<<structured type>>
EmployeeTY
emp_id : char(7)
emp_name : PersonName
date_of_birth : date
gender : char
phone_num : set(varchar(12))
salary : money

OF

<<object table>>
Employee

<<structured type>>
FullTimeEmployeeTY
superannuation_fund : varchar(20)

<<structured type>>
ManagerTY
managerial_position : varchar(20)
salary_supplement : money

OF

<<object table>>
Manager

create type ManagerTY


under FullTimeEmployeeTY
as (managerial position varchar (20),
salary_supplement money)
instantiable
final;
create table Manager of ManagerTY
under Employee;
. 8.11. 

, SQL:1999  . 
(, , ) . SQL:1999
.

8.3.2.
, , UML, 
,
UML. UML 
.

8.3.

337

, ,
SQL:1999, . 
SQL:1999 , ,
, SQL:1999.
, , Oracle8 ( 
8.1.5.0.0 Oracle8i) , . 
 
, ,
.
..

8.3.2.1.
8.5.
4.6, . 4.3 (. 4.2.1.2.3). 8.1 (. 8.2.2.1).
, , . 8.5.

<<structured type>>
PersonLongNameTY

<<structured type>>
ContactTY

family_name : varchar(30)
first_name : varchar(20)
middle_initial : char

contact_id : integer
phone : set(varchar(15))
fax : set(varchar(15))
email : set(varchar(50))

<<structured type>>
EmployeeTY
employee_id : char(8)
employee_name : PersonLongNameTY

<<row type>>
person_short_name
family_name : varchar(30)
first_name : varchar(20)

OF
<<object table>>
Contact
person_short_name : row type

OF
<<object table>>
Employee

create table Contact of ContactTY


(person_short_name row
(family_namevarchar(30)
first_name varchar(20)));

. 8.12.  
( )

338

8.

,
 (. 8.5). SQL:1999 , 
PersonShortName
PersonLongName.
. 8.12 .
PersonLongName .
EmployeeTY. PersonShortName
(person_short_name) (
 !). Contact
ContactTY, , person_short_name,
.
person_short_name .

8.3.2.2.
8.6.

4.8, . 4.5 (. 4.2.2.3).
, . 8.2.2.2 8.3.2.1.
,
, . 8.6 (. 8.2.2.2). ,
, -, . 8.6,
( ).

. 8.13.
, , , 
. ,
.

8.3.2.3.
8.7.

4.9, . 4.6 (. 4.2.3.3).
UML-,
. 4.6, .
8.3, .
, ( ) .

,
UML UML. ,
, . 
Student AcademicRecord Student 
, AcademicRecord.
. 8.14. set (AcademicRecordTY).

8.3.

<<structured type>>
OrganizationTY

<<structured type>>
ContactTY

organization_id : integer

contact_id : integer

phone : set(varchar(15))
fax : set(varchar(15))
email : varchar(30)

phone : set(varchar(15))
fax : set(varchar(15))
email : set(varchar(50))

is_current : boolean

339

<<structured type>>
TaskTY
description : varchar(255)

OF

<<object table>>
Organization
postal_address : row type
courier_address : row type
contact : set(ref(Contact))
task : set(ref(Task) )

<<structured type>>
EventTY
description : varchar(255)
created_dt : date
due_dt : date
completed_dt : date
priority : char

created_dt : date
value : money

OF

<<object table>>
Task
created_emp : ref(Employee)
event : list(ref(Employee))
organization : ref(Organization)
contact : set(ref(Contact))

OF

<<object table>>
Contact
person_short_name : row type
postal_address : row type
courier_address : row type
organization : ref(Organization)
task : set(ref(Task) )

<<structured type>>
EmployeeTY
employee_id : char(8)

OF
OF
<<object table>>
Employee
<<object table>>
Event
task : ref(Task)
created_emp : ref(Employee)
due_emp : ref(Employee)

person_long_name : row type


created_task : list(ref(Task) )
created_event : set(ref(Event))
due_event : list(ref(Event))
completed_event : set(ref(Event))

. 8.13. 
( )

UML Course CourseOffering


. 
. ,

340

8.

, SQL:1999, 
ref (.. 
).
<<structured type>>
AcademicRecordTY

<<structured type>>
CourseTY

course_code : char(7)

course_code : char(7)

year : date
semester : integer

course_name : varchar(30)
credit_points : integer

grade : varchar(2)

OF
<<structured type>>
StudentTY
student_id : char(8)
student_name : varchar(50)
current_fees : money
academic_record : set(AcademicRecordTY)

OF

<<object table>>
Student

<<object table>>
Course
course_offering : list(ref(CourseOffering))

<<structured type>>
CourseOfferingTY
year : date
semester : integer
enrolment_quota : integer

course_off : list(ref(CourseOffering))

OF
<<structured type>>
AcademicInChargeTY
<<object table>>
CourseOffering

OF

course : ref(Course)
student : list(ref(Student))
academic_in_charge : ref(AcademicInCharge)

<<object table>>
AcademicInCharge
course_off : list(ref(CourseOffering))

. 8.14. 
( )

8.3.

341

8.3.2.4.
8.8.

4.10, . 4.7 (. 4.2.4.3). . 8.2.2.4.
, , . 8.8. (. 8.2.2.4).
,
, ,
. : is_in_stock ( ) number_currently_available ( ).


.
SQL:1999, , ref
. ref
, .
MovieTitle VideoMedium 
, VideoMedium (.. BetaTape, VHSTape DVDDisk)
MovieTitle. , , 
MovieTitle . . 8.15.
<<structured type>>
RentalConditionsTY

<<structured type>>
VideoMediumTY

rental_period_in_days : integer
rental_charge_per_period : money

video_condition : char
rental_cond : RentalConditionsTY

<<structured type>>
MovieTitleTY
movie_code : char(10)
movie_title : varchar(100)
director : varchar(30)

<<structured type>>
VideoTapeTY

<<structured type>>
VideoDiskTY

is_taped_over : boolean

different_langages : boolean
different_endings : boolean

OF
OF
<<object table>>
MovieTitle
beta_tape : set(ref(BetaTape))
vhs_tape : set(ref(VHSTape))
dvd_disk : set(ref(DVDDisk) )

OF

<<object table>>
BetaTape
movie_title : ref(MovieTitle)

<<object table>>
DVDDisk

OF

movie_title : ref(MovieTitle)

<<object table>>
VHSTape
movie_title : ref(MovieTitle)

. 8.15. 
( )

342

8.

8.4.

. () 
. 1990
()
, ODMG
.
, 
. , Oracle, IBM
Informix, ,
. ( Informix 
2001 IBM. . .).
, ,
API , 

, , .
,
, , , 
. , 
, 
, , 
.
( ) 
SQL92. ANSI ISO 1992 .
(Oracle, DB2, Sybase, Informix, Microsoft
SQL Server .) ,
. , (, (trigger))
, 
SQL:1999.

8.4.1.
, , . 
, ,
, . , 
, ( 
). ,
, , 
( , ).
, ,
. .
, .
, .
,
. 
, , 
.

8.4.

343

(,
).
.
.
.

(relational table), . 

.

. 
.
. 
(referential integrity).
. 8.16 .
, ,
, . 
, .
, . 8.16,
. 9.

. 8.16.

344

8.

8.4.1.1. ,
.
, ,
() ( ) . ,
(atomic domains) ( ).
(domain) , 
. (, gender char(1))
(, gender Gender).
Gender . 
.
create domain Gender char(1);


.
. , , 
.
, ,
, .. .
, 
.  
.
, (, (city)
, ).
(, (age)
18 80).
(, (color) ,
).
, (,
).
(, K).
,
. , 
, . 
 .

8.4.1.2.
(relational table)
. , ,
(.. ).
( ). ,
, .
, 
NULL. NULL 
:
(. 8.2.1.1).

8.4.

345

,
, (primary key).
( ) ,
.
. 
(primary key).
(candidate) (alternative) .
. , (
)
, , 
, . 
OID ( 
, , , ).
UML 
,
,
. . 8.17 .
DB2 IBM.
Employee
emp_id
family_name
first_name
date_of_birth
gender
phone_num1
phone_num2
salary

CHAR(7)
VARCHAR(30)
VARCHAR(20)
DATE
Gender
VARCHAR(12)
VARCHAR(12)
DEC(8,2)

<pk> not null


<ak> not null
not null
<ak> not null
not null
null
null
null

. 8.17.

Employee .
NULL. emp_id
. {family_name, date_of_birth} 
() . gender Gender.
, ,
, 

. : family_name
first_name. .
(phone_num1, phone_num2), 
.
, CASE, 
, . 
Gender 
, .

346

8.

============================================================
-- Domain: Gender
============================================================
create distinct type Gender as CHAR(1) %WITHCOMPAR%;
============================================================
-- Table: Employee
============================================================
create table Employee (
emp_id

CHAR(7)

not null,

family_name

VARCHAR(30)

not null,

first_name

VARCHAR(20)

not null,

date_of_birth

DATE

not null,

gender

Gender

constraint

C_gender

not null

check (gender in ('F','M','f','m')),

phone_num1

VARCHAR(12),

phone_num2

VARCHAR(12),

salary

DEC(8,2),

primary key (emp_id),


unique (date_of_birth, family_name)
);

8.4.1.3.

.
. ,
.

.
(foreign key)
, NULL,
. 
. 
, , 
, , 
.
. 8.18 . 
Employee Department 
Employee dept_id.
Employee NULL,
dept_id Department (
).

8.4.

Department

347

Employee

dept_id
SMALLINT
<pk> not null
dept_name VARCHAR(50)
not null
address
VARCHAR(120)
null

dept_id = dept_id
Upd(R); Del(R)

O..n

emp_id
dept_id
family_name
first_name
date_of_birth
gender
phone_num1
phone_num2
salary

CHAR(7)
SMALLINT
VARCHAR(30)
VARCHAR(20)
DATE
Gender
VARCHAR(12)
VARCHAR(12)
DEC(8,2)

<pk> not null


<fk> null
<ak> not null
not null
<ak> not null
not null
null
null
null

. 8.18.

, , 
, . 
, 
delete update. , ,
Employee Department (.. 
dept_id). .
1. Upd(R); Del(R) update delete (.. 
, Employee 
, Department).
2. Upd(C); Del(C) (..
Employee, Department).
3. Upd(N); Del(N) null (..
Department dept_id
Employee NULL).
4. Upd(D); Del(D) ,
(.. Department 
dept_id Employee
).
Student
stud_id CHAR(8)
<pk> not null
name

VARCHAR(50)

CourseOffering
crs_name VARCHAR(50) <pk> not null
semester CHAR(1)
<pk> not null

not null

crs_name = crs_name
semester = semester
Upd(R); Del(R)

stud_id = stud_id
Upd(R); Del(C)

O..n

StdToCrsOf f
stud_id
CHAR(8)
<fk1> not null
crs_name VARCHAR(50) <fk2> not null
semester CHAR(1)
<fk2> not null

. 8.19.

O..n

348

8.

,
,
Student CourseOffering (. 8.3 . 8.2.1.2).
, , 
, 
(intersection table) StdToCrsOff,
. 8.19. 

.

8.4.1.4.

 .
 . 
( SQL:1999) 
(trigger).
, SQL, 
() 
, .
SQL: insert, update
delete.
,
rule SQL (. 8.4.1.1). , 
, Employee 
, . 
SQL insert, update delete 
, .

. ,  ,
Department ()
Employee, , 
, . 
( ) dept_id
NULL.  .
, .

, .
, 
. , 

. , ,
CASE 
.
, ,
CASE Sybase.
Del(r) .. Department ,
Employee, .

8.4.

349

create trigger keepdpt


on Department
for delete
as
if @@rowcount = 0
return /* avoid firing trigger if no rows affected
*/
if exists
(select * from Employee, deleted
where Employee.dept_id =
deleted.dept_id)
begin
print 'Test for RESTRICT DELETE failed. No deletion'
rollback transaction
return
end
return
go

, SQL delete (
)  . ,
.
Department , Sybase ( 
) deleted.
dept_id Employee
deleted, , ,
, . ,
, 
. Department .

8.4.1.5.
(relational view) (
. . .) SQL.
SQL , 
SQL, 
/ (. 8.16).
EmpNoSalary
Employee.emp_id
Employee.dept_id
Employee.family_name
Employee.first_name
Employee.date_of_birth
Employee.gender
Employee.phone_num1
Employee.phone_num2
Employee

. 8.20.

350

8.

. 8.20 EmpNoSalary
Employee salary.
create view ,
,
SQL .
======================================================
-- View: EmpNoSalary
-======================================================
create view EmpNoSalary () as
select Employee.emp_id, Employee.dept_id,
Employee.family_name, Employee.first_name,
Employee.date_of_birth, Employee.gender,
Employee.phone_num1, Employee.phone_num2
from Employee;

, 
; 
, 
; . 
,
.

.

 .
(SQL
insert, update delete) 
. SQL92
.

8.4.1.6.
, ,

(normalization).
(). .
1
2
3
(  (BoyceCodd))
4
5
, ,
. , , 1 . ,
, 1
( ).

8.4.

351

.
,
(insert, update, delete) . 
,
, 
, . ,
.
, ? 
,
. , ,
. , ,

SQL join.

.
(Date) [17], (Maciaszek) [51], (Silberschatz) [79], 
(Ramakrishnan) (Gehrke) [67]. , 
, ,
.
? 
, , 
.
, .. ,
, ,
. 
, .
, 
, .. , 
,
. ,
, 
, .

8.4.2.
UML 
. , 

. ,
. 

, .. (. 9.1.2.1).
ER
ER (, [51], [22]).

. ,
( SQL92), 
.

352

8.

8.4.2.1.

1 . . ,
, . 8.2.2.1, ( 
) UML 
. .

8.9.
4.6, . 4.3 (. 4.2.1.2.3). , 8.1.
Contact Employee , .

. 8.21. 
Oracle. contact_name
Contact. (Contact) 
. , 
. ContactPhone.
Employee :
family_name, first_name middle_initial. , 
employee_name
.
Contact
contact_id
contact_name
fax
email

SMALLINT
<pk> not null
VARCHAR2(50)
not null
VARCHAR2(15)
null
VARCHAR2(15)
null

contact_id = contact_id
O..n

Employee
employee_id CHAR(8)
<pk> not null
family_name VARCHAR2(30)
not null
first_name
VARCHAR2(20)
middle_initial CHAR

not null
null

ContactPhone
phone
VARCHAR2(15) <pk> not null
contact_id SMALLINT
<fk> not null

. 8.21.  (
)

8.4.2.2.

.

.

( 

8.4.

353

), 
( ).

.
( , ) 
, . 8.19.

8.10.

4.8, . 4.5 (. 4.2.2.3).
, . 4.5, .

 
UML . ( DB2) 
. 8.22.
; ,
. 8.21, .
NULL .
PostalAddress
CourierAddress , Organization Contact
.
, 
(..
Organization Contact).

8.4.2.3.

.
(. 8.4.2.2) 
. ,
, ( 
) .
(.. ) 
 . 
. 
( ) 
( , ).

8.11.

4.9, . 4.6 (. 4.2.3.3).
, . 4.6, .

Student
AcademicRecord Course Course
Offering. 
.

354

8.

Organization
organization_id
INTEGER

organization_id = organization_id

organization_name VARCHAR(80)
phone
VARCHAR(15)
fax
email

VARCHAR(15)
VARCHAR(30)

is_current

CHARA CTER

contact_id

Contact
SMALLINT

organization_id INTEGER
contact_name VARCHAR(50)
fax
email

PostalAddress
postal_id
INTEGER

VARCHAR(15)
VARCHAR(15)

organization_id INTEGER
contact_id
SMALLINT
street
organization_id = organization_id po_box

organization_id = organization_id

organization_id = organization_id

task_id = task_id

event_id
task_id

VARCHAR(80)
VARCHAR(20) contact_id = contact_id

city
state
post_code

VARCHAR(50)
VARCHAR(30)
VARCHAR(8)

country

VARCHAR(50)

CourierAddress
courier_id
INTEGER
organization_id
INTEGER
contact_id
SMALLINT
street_and_directions VARCHAR(255) contact_id = contact_id
city
VARCHAR(50)
state
VARCHAR(30)
country
VARCHAR(30)

Task
task_id
SMALLINT
organization_id INTEGER
contact_id
SMALLINT
employee_id
CHAR(8)
description
VARCHAR(255)
created_dt
DATE
value
FLOAT

contact_id =
contact

contact_id = contact_id
ContactPhone
phone
VARCHAR(15)
contact_id SMALLINT
employee_id = employ ee_id

Event
INTEGER
SMALLINT

created_emp_id
due_emp_id
completed_emp_id
description

CHAR(8)
CHAR(8)
CHAR(8)
VARCHAR(255)

created_dt
due_dt
completed_dt
priority

DATE
DATE
DATE
SMALLINT

Employee
employee_id CHAR(8)
family_name VARCHAR(30)
employee_id = due_emp_id
first_name
VARCHAR(20)
employee_id = completed_emp_id middle_initial CHAR(1)
employee_id = created_emp_id

. 8.22. ( )

UML, . 4.6, ( 
) AcademicRecord
Course. , 

8.4.

355

AcademicRecord Course.
, AcademicRecord course_code 
.
Course. . 8.23 ( Informix).
AcademicRecord
student_id = student_id student_id

NCHAR(8)

<pk.fk1> not null course_code = course_code

course_code CHAR(7)

<pk.fk2> not null

year

DATE

<pk>

not null

semester
grade

NCHAR
<pk>
VARCHAR(2)

not null
not null

Student

Course

student_id
NCHAR(8)
<pk> not null
student_name VARCHAR(50)
not null

course_code CHAR(7)
<pk> not null
course_name VARCHAR(30)
not null

current_fees

credit_points SMALLINT

MONEY

null

null

course_code = course_code
student_id = student_id
CourseOffering
StdToCrsOff
student_id NCHAR(8) <pk.fk1> not null
crsoff_id

SERIAL

<pk.fk2> not null

crsoff_id = crsoff_id

crsoff_id
course_code

SERIAL
CHAR(7)

<pk>
not null
<ak,fk> not null

year
semester

DATE
NCHAR

<ak>
<ak>

enrolment_quota
SMALLINT
academic_in_charge VARCHAR(60)

not null
not null
null
null

. 8.23. ( )

Student CourseOffering
, 
. StdToCrsOff
, 
.
CourseOffering
{course_code, year, semester}. , 
StdToCrsOff.
CourseOffering, 
. crsoff SERIAL ( Informix 
SERIAL;
, Sybase
IDENTITY, Microsoft SQL Server UNIQUEIDENTIFIER Oracle SE_QUENCE).

8.4.2.4.
, 
, , . ,
, , 
, , ,
..

356

8.

, 
. 8.24.
( 
).
1. .
2. .
3. .
4. .
Person

Employee

Student

StudentEmployee

. 8.24. , 

. 8.25.
. ,
. ,
person_name Person Employee,
Student StudentEmployee? 
, 
person_name .
. 8.26 ( Mi
crosoft SQL Server). Person
.
(is_employee is_student) , ,
.
,
Person . Person ,
. . 8.27.
. 8.28 ( Informix),
 , Person .
, . 8.25, , 
, .
null BOOLEAN.

8.4.

person_id = person_id

Person
person_id <pk>

Employee
employee_id <pk>
person_id
<fk>

employee_id = employee_id

357

person_id = person_id

Student
student_id <pk>
person_id <fk>

StudentEmployee
student_id = student_id
employee_id <pk,fk1>
student_id
<pk,fk2>

. 8.25.
Person
person_id
uniqueidentifier <pk> not null
is_employee char(1)
null
is_student
char(1)
null

. 8.26.
Employee
employee_id <pk>

Student
student_id <pk>

StudentEmployee
employee_id = employee_id employee_id <pk,fk1> student_id = student_id
student_id

<pk,fk2>

. 8.27.
Employee

Student

employ ee_id NCHAR(8) <pk> not null


is_student
BOOLEAN
not null

student_id
NCHAR(10) <pk> not null
is_employee BOOLEAN
not null

. 8.28.

( Sybase) . 8.29
(BetaTape, VHSTape DVDDisk).
: video_condition, rental_period_in_days rental_charge_
per_period.
rental_period_in_days one rental_charge_per_period.

358

8.

8.12.

4.10, . 4.7 (. 4.2.4.3). , 8.4 (. 8.2.2.4).
, , . 4.7,
, . 8.8 ( 8.4). .
,
is_in_stock number_currently_available. ,
(..
BetaTape, VHSTape DVDDisk).

movie_code = movie_code

movie_code
movie_title
director
is_in_stock

MovieTitle
char(10)
<pk> not null
varchar(100)
not null
varchar(30)
null
bit
not null

movie_code = movie_code

movie_code = movie_code
BetaTape
beta_id
identity <pk> not null
movie_code
char(10) <fk> not null
video_condition
char(1)
null
rental_period_in_days
smallint
not null
rental_charge_per_period numeric
not null
is_taped_over
bit
not null

vhs_id
movie_code

DVDDisk
dvd_id
identity <pk> not null
movie_code
char(10) <fk> null
video_condition
char(1)
null
rental_period_in_days
smallint
not null
rental_charge_per_period numeric
not null
different_languages
bit
not null
different_endings
bit
not null

VHST ape
identity

<pk> not null

char(10) <fk> not null

video_condition
char(1)
rental_period_in_days
smallint
rental_charge_per_period numeric

null
not null
not null

is_taped_over

not null

bit

. 8.29. ( )

is_taped_over, different_languages, different_endings


is_in_stock bit. bit
null ( bit : 0 1).
is_in_stock (1), 
, , .
, 
. bit 

359

, , ..
() , .
number_currently_available
, . ,
, MovieTitle.
, , 
is_in_stock.

,
. 
, . 
,  .
, .
.
UML 
.
.

. .
UML : ISA EXTENDS. 
UML .

.
.
, 
UML. .
UML : OF UNDER.
. 
, , ,
. , .
, , 
UML, . , 
.

1.

: ,
.

2.

? ?

3.

4.

? UML?

5.

?
UML?

6.

inverse .

360

8.

7.

ISA EXTENDS ?

8.

(row type) ? ? .

9.

10. ? .
11. , , ?
12. OF UNDER ?
13. ?
UML?
14. .
15. ? ?
16. ? .

1.

,
, 1 7.
. .

2.

,
, 1 7.
. .

3.

,
, 1 7.
. .

Оценить