Download Intro to the AS/400

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Relational algebra wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Database wikipedia , lookup

Clusterpoint wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
Intro to the AS/400
Chapter 11 - Logical Files
Copyright 1999 by Janson Industries
Objectives





Explain the three primary data models
and their differences
Explore the major features of
database management systems
Show the difference between logical
and physical files
Explain the relationship between
logical and physical files
Use DDS to create simple and join
logical files
2
Copyright 1999 by Janson Industries
What Is a Database?



A database is made up of related
“groups of data”
A DBMS is a collection of programs
that allows the user to create, maintain
and relate these groups of data
There are three types of databases
 Hierarchical
 Network
 Relational
3
Copyright 1999 by Janson Industries
Data Relationships

Number of relationships a record has
with records from another group
 One-to-one
 One-to-many
 Many-to-many

Direction of access required
 Unidirectional
 Bi-directional
4
Copyright 1999 by Janson Industries
Hierarchical Database




Can only support a parent-child
relationship (one-to-many, unidirectional)
Relationships between records are stored
One “root” data group is the only entry
point into the database (I.e. access to any
data group must be through the root)
To access a record, the data record key,
as well as, the keys of all parent records
must be provided
5
Copyright 1999 by Janson Industries
Hierarchical Database Pros & Cons

Advantages
 Stored
relationships mean fast
retrieval

Disadvantages
 Stored
relationships take up space
 Stored
relationships must be
maintained, slowing updates
 Some
data does not relate one-tomany and users want bi-directional
access
6
Copyright 1999 by Janson Industries
Network Database



Like hierarchical DB’s, relationships
between data records are stored
Allows multiple entry points into a
database
Supports many-to-many relationships
and bi-directional access
7
Copyright 1999 by Janson Industries
Network Database Pros & Cons

Advantages
 Supports

complex relationships
Disadvantages
 Complex
relationships require more
space, take longer to update and
retrieval is slower
 Because
of the complexity,
specialized personnel are needed
8
Copyright 1999 by Janson Industries
Relational Database





Copyright 1999 by Janson Industries
Groups of data are viewed as tables
(also called relations) with rows and
columns not records and fields
No stored relationships
Access to database can be through
any table and doesn’t have to be
defined
Tables can be accessed by any field
To relate information between different
tables, the relational model uses
duplicate data fields
9
Relational Database Pros & Cons

Advantages
 Easy
to understand, use and learn
 No
stored relationships therefor faster
updating and less space

Disadvantages
 Requires
data redundancy - extra
space, longer to update
 Slow
retrieval
10
Copyright 1999 by Janson Industries
DBMS Features

Data access controls

Backup and recovery

Data integrity

Data manipulation

Query language

Alternative views
11
Copyright 1999 by Janson Industries
AS/400 Features

Data access controls
 Object

security (Chap 15)
Backup and recovery
 GO
Backup
 SAV commands

Data integrity
 Referential
constraints
 Trigger programs
 DDS keywords
12
Copyright 1999 by Janson Industries
AS/400 Features

Data manipulation
 DFU
 SQL/400

Query language
 QUERY/400
 SQL/400

Alternative views
 Logical
files
 SQL views
13
Copyright 1999 by Janson Industries
A Logical File



Refers to data that exists in a physical file
Can reference data from many physical
files
Contains:
Field definitions
An access path
14
Copyright 1999 by Janson Industries
Logical File

Created by compiling a source physical file
member with type = LF
Library
Source
Physical
File
Logical
File
Compile
Type = LF
15
Copyright 1999 by Janson Industries
Logical File

Acts as an alternate index to physical file data
Library
Logical
File
Data Physical
File
Data Physical
File
16
Copyright 1999 by Janson Industries
Logical/Physical Relationship



Logical files can be used to update
physical file data (except join logical
files)
A physical file cannot be deleted if
there is a dependant logical file
You can use DSPDBR to find a
physical files’ dependant logical files
17
Copyright 1999 by Janson Industries
Relational Operands

Select

Project

Union

Join
18
Copyright 1999 by Janson Industries
Select



SELECT retrieves certain rows from a
relational table, based on a condition
SELECT FROM table name WHERE
condition
Conditions take the form of:
Field Comparison Value/Field
e.g. Salary > 20,000
Gender = “F”
Date
< CURDATE
19
Copyright 1999 by Janson Industries
Select
Lname
Jones
Smith
Adams
Conner
Fname
Adrian
Pat
Chris
Dale
Gender
M
F
F
M
Salary Dept
14000
716
23000
630
65000
630
34000
924
SELECT FOR Gender = “F”
Smith
Adams
Pat
Chris
F
F
23000
65000
630
630
20
Copyright 1999 by Janson Industries
Project

Project returns only specified columns (but all rows)
Jones
Smith
Adams
Conner
Adrian
Pat
Chris
Dale
M
F
F
M
14000
23000
65000
34000
716
630
630
924
PROJECT ON Lname Dept
Jones
Smith
Adams
Conner
716
630
630
924
21
Copyright 1999 by Janson Industries
Project
Projects & Selects can also be performed together
Lname
Jones
Smith
Adams
Conner
Fname
Adrian
Pat
Chris
Dale
Gender
M
F
F
M
Salary Dept
14000
716
23000
630
65000
630
34000
924
PROJECT (SELECT FOR Gender = “F”) ON Lname Dept
Smith
Adams
630
630
22
Copyright 1999 by Janson Industries
Union


A union of two tables combines and
sorts the rows of multiple tables into
a defined sequence
The total number of rows from the
result of a union is equal to the
combined number of rows in each
table
23
Copyright 1999 by Janson Industries
Union
Jones
Smith
Adams
Conner
Adrian
Pat
Chris
Dale
14000
23000
65000
34000
Evans
Rudd
Kahn
Dole
Joan
Scott
Bill
Rene
42000
81000
18000
36000
UNION ORDER BY Salary
Jones
Kahn
Smith
Conner
Dole
Evans
Adams
Rudd
Copyright 1999 by Janson Industries
Adrian
Bill
Pat
Dale
Rene
Joan
Chris
Scott
14000
18000
23000
34000
36000
42000
65000
81000
24
Joins




Joins appear to combine data from
different tables
A general join matches every row in one
table with every row in another table
An equijoin matches rows between tables
that have the same values in a column(s)
A natural join matches rows like an
equijoin but eliminates duplicate columns
in the result table
25
Copyright 1999 by Janson Industries
Simple Logical Files


Allow you to perform the SELECT and
PROJECT functions
Reference a physical file with the PFILE
record level keyword
R DEPTREC
LNAME
DEPT

PFILE(PF1)
Include all or some of the fields from the
physical file with field level specifications
(I.e. perform a project)
26
Copyright 1999 by Janson Industries
Simple Logical Files


Select or omit rows with Select or Omit
specifications
Select or Omit specifications identified
with a S or O in column 17 and follow
field and key specifications
R DEPTREC
LNAME
DEPT
S GENDER

Condition: Field
PFILE(PF1)
COMP(EQ 'F')
Comparison
Value
27
Copyright 1999 by Janson Industries
Union

Use PFILE keyword to identify the files
R EMPREC
LNAME
FNAME
GENDER
SALARY
DEPT
K SALARY

PFILE(PF1 PF2)
Only fields found in all files can be
specified
28
Copyright 1999 by Janson Industries
Joining Files


Logical files allow you to perform a JOIN
JFILE - record level keyword that
identifies the files to be joined
R R1FMT
J
J
FLDA
FLDC
Copyright 1999 by Janson Industries
JFILE(PF1 PF2 PF3)
JOIN(1 2)
JFLD(FLDA FLDA)
JOIN(2 3)
JFLD(FLDB FLDC)
JREF(1)
29
Joining Files


R R1FMT
J
J
FLDA
FLDC
Join specification - defines the basis
for joining the files (J in column 17)
Join specs follow record specs and
there is one for each two files joined
JFILE(PF1 PF2 PF3)
JOIN(1 2)
JFLD(FLDA FLDA)
JOIN(2 3)
JFLD(FLDB FLDC)
JREF(1)
JOIN keyword identifies the two files
to be joined
 JFLD keyword(s) identifies the field(s)
that
will
be
used
to
join
the
records
Copyright 1999 by Janson Industries

30
Points to Remember




There are three types of databases:
hierarchical, network, and relational
Relational DBMS’s provide the
capability to perform: select, project,
union and join
With these relational operands you
can create various user views of data
AS/400 logical files provide relational
DBMS functions
31
Copyright 1999 by Janson Industries