Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
BD / Slides / English / Lecture 04E-Network Data Model.ppt
Скачиваний:
18
Добавлен:
20.02.2016
Размер:
302.59 Кб
Скачать

Lecture 4. Network Data Model

The first and the last member record in the set occurrence

Syntax:

FIND FIRST|LAST [record­name] RECORD IN [set­name] SET

Example:

FIND FIRST Lecture RECORD IN Has SET;

TEACHER

 

T1

 

T2

 

 

 

 

 

 

Has

 

 

 

 

 

LECTURE

L1

L2

L3

L4

L5

 

 

 

 

 

Is_taught_at

 

 

 

 

 

SUBJECT

S1

 

 

S2

S3

 

 

 

 

 

Current occurrence of the set “Has”

L1 - the first member record of the set “Has”

Error_Status != 0 – the record occurrence do not have member records

CSF NAU

21

Lecture 4. Network Data Model

Location of the owner record of the current set occurence

Syntax:

FIND OWNER OF [set­name] SET

Example:

FIND OWNER OF Has SET

TEACHER

T1

T2

 

Has

 

 

 

LECTURE

L1 L2 L3

L4

L5

Is_taught_at

 

 

 

SUBJECT

S1

S2

S3

Current occurrence of the set “Has”

L2 - current member record of the set “Has”

T1 - owner record of the set “Has”

CSF NAU

22

Lecture 4. Network Data Model

Example

X = ”T1”;

FIND Teacher RECORD BY DATABASE KEY X; FIND LAST Lecture RECORD IN Has SET;

FIND OWNER OF Is_taught_at SET; FIND LAST Lecture RECORD IN Is_taught_at SET; FIND NEXT Lecture RECORD IN Has SET;

FIND OWNER OF Is_taught_at SET;

T1

L3

S2

L4

L5

S3

 

TEACHER

 

 

 

 

T1

 

 

 

T2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Has

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

L1

 

L2

 

L3

 

L4

 

L5

 

 

LECTURE

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Is_ taught_at

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CSF NAU

 

 

 

 

 

S1

 

 

S2

S3

 

SUBJECT

 

 

 

 

23

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Lecture 4. Network Data Model

Put a record occurrence into the database

create a record occurrence in UWA;

execute the command STORE.

Syntax:

STORE [record­name] RECORD

Example:

STORE Teacher RECORD

Stored record automatically connected to the current set occurrence.

CSF NAU

24

Lecture 4. Network Data Model

Attaching record occurrence from DB to the set occurrence

Make required set occurrence the current of set type

Make inserted record occurrence the current one

Execute the command INSERT

Syntax:

INSERT [record­name] RECORD INTO [set­name] SET

Example:

X = 31; FIND Teacher RECORD BY DATABASE KEY x; Y = 24; FIND Lecture RECORD BY DATABASE KEY y; INSERT Lecture RECORD INTO Has SET;

CSF NAU

25

Lecture 4. Network Data Model

Remove a record occurrence of a certain type from a certain set occurrence

Make designated record be the current one

Execute the command REMOVE

Syntax:

REMOVE [record­name] RECORD FROM [set­name] SET

Example: Remove all lectures of the teacher with DBK 31.

x=31; FIND Teacher RECORD BY DATABASE KEY x; Loop: FIND NEXT Lecture RECORD IN Has SET;

IF Error_Status=0 THEN

BEGIN; REMOVE Lecture RECORD FROM Teacher SET; GO TO Loop;

END;

CSF NAU

26

Lecture 4. Network Data Model

Updating record occurrence

The MODIFY command copies values from a record in UWA into the current record occurrence of the DB.

Example: For teacher with DBK 31 change name to “Smith”.

x=31; FIND Teacher RECORD BY DATABASE KEY x; GET Teacher RECORD;

Teacher.Name = ”Smith”; MODIFY RECORD;

CSF NAU

27

Lecture 4. Network Data Model

Deleting record occurrence from DB

The DELETE command removes from DB the current record occurrence

The set owner may be deleted when this set do not contains member records

Syntax:

DELETE [record­name] RECORD

Example: Delete record with DBK 21.

x=21; FIND Lecture RECORD BY DATABASE KEY x; DELETE Lecture RECORD;

CSF NAU

28

Lecture 4. Network Data Model

Advantages and drawbacks

The network data model basically has the same advantages and drawbacks as hierarchical data model.

The only basic difference of the network data model in comparison with hierarchical data model is the opportunity to represent many-to-many relationships.

CSF NAU

29