Professional Documents
Culture Documents
Database Fundamentals TH
Database Fundamentals TH
Database Fundamentals TH
: Neeraj Sharma, Liviu Perniu, Raul F. Chong, Abhishek Iyer, Adi-Cristina Mitea,
Chaitali Nandan, Mallarswami Nonvinkere, Mirela Danubianu
: .
1 ( 2555)
Copyright IBM Corporation 2010. All rights reserved.
IBM Canada
IBM Director of Licensing
IBM Corporation
North Castle Drive
Armonk, NY 10504-1785
U.S.A.
Double-byte character set (DBCS)
:
Intellectual Property Licensing
Legal and Intellectual Property Law
IBM Japan, Ltd.
3-2-12, Roppongi, Minato-ku, Tokyo 106-8711
1 14
5 15
1 - 2 20
1.1 ............................................................................................ 20
1.2 ....................................................................... 21
1.2.1 ......................................................... 21
1.3 (Information Models) (Data Models)2 23
1.4 .................................................................................. 24
1.4.1 (Network model)2 25
1.6 .............................................................................................................. 31
1.7 ..................................................................................................... 31
1.8 3 31
2 3 34
2.1 3 34
2.2 3 36
2.2.1 (Attributes)............................................................................. 36
2.2.2 (Domains)....................................................................................... 37
2.2.3 (Tuples)........................................................................................... 37
2.2.4 (Relations)...................................................................................... 38
2.2.5 (Schemas)................................................................................... 38
2.2.6 (Keys)................................................................................................. 39
2.3 4 41
2.3.1 ..................................................................... 41
2.3.2 (Referential integrity)..................... 42
2.3.3 (Semantic integrity constraints)............... 43
2.4 .......................................................................................... 45
2.4.1 Union........................................................................................................ 45
2.4.2 Intersection.............................................................................................. 46
2.4.3 Difference................................................................................................ 46
2.4.4 Cartesian product.................................................................................... 47
2.4.5 Selection.................................................................................................. 48
2.4.6 Projection................................................................................................. 49
2.4.7 Join.......................................................................................................... 50
2.4.8 Division..................................................................................................... 52
2.5 ......................................................................................... 52
2.5.1 (Tuple-oriented relational calculus).................. 53
5.2.7 ..................................................................113
5.3 SQL1114
5.3.1 (Select)..............................................................................114
5.3.2 (Insert)............................................................................115
5.3.3 (Delete)...............................................................................116
5.3.4 (Update).......................................................................116
5.4 (Table Joins)..................................117
5.4.1 Inner Join...........................................117
5.4.2 Outer Joins.......................................118
5.5 Union, Intersection, Difference.......................................121
5.5.1 Union......................................................................................................121
5.5.2 Intersection............................................................................................122
10
5.9 3................................................127
5.10 ..........................................................................................................132
5.11 .................................................................................................132
5.12 1133
6 Stored Procedure ...............................................................136
6.1 IBM Data Studio......................................................................136
6.3.3 ................................................................................145
6.3.4 ..........................................................................146
6.4 ........................................................................................................146
6.5 ...................................................................................................146
6.6 1147
7 SQL ..................................................150
11
7.4.2 JDBC.......................................................................................................163
7.5 pureQuery................................................................................................164
7.5.1 IBM pureQuery Client Optimizer............................................................166
7.6 ........................................................................................................167
7.7 ...................................................................................................168
7.8 1168
8 XML1170
8.1 XML..........................................................................................170
8.1.1 XML element ..........................................................171
8.1.2 XML (XML attribute).........................................................172
8.1.3 Namespaces...........................................................................................173
8.1.4 (Document Type Definition: DTD)1173
12
8.9 ........................................................................................................199
8.10 .................................................................................................199
8.11 2200
9 ...................................................................204
9.1 . .........................................................204
9.1.1 0206
9.1.2 (Access Control)......................................................207
9.1.3 .......................................207
9.1.4 (Views)..............................................................................................212
9.1.5 (Integrity Control)...............................................212
9.1.6 .......................................................................................212
9.2 .............................................212
9.2.1 ..............................................................................212
9.2.2 ..............................................................................213
9.3 ............................................................................................................213
9.4 ...................................................................................................214
9.5 2214
10 - . ............................................................216
10.1 (Cloud computing) ?..............................216
10.1.1 Cloud..............................................................................217
10.1.2 Cloud computing...................................................217
10.1.3 Cloud....................................................................................218
10.1.4 Cloud............................................................221
10.1.5 Cloud...............................................................................222
10.2 ..........................................................223
10.2.1 2224
10.2.2 2225
10.2.3 .................................................................225
10.2.4 ....................................................226
10.2.5 2 226
10.2.6 DB2 .......................................................................................227
10.3 (Business intelligence and appliances)..............................227
10.4 db2university.com: Cloud ()..........227
13
10.4.1 Moodle...................................228
10.4.2 openID .................................................230
10.4.3 Cloud Amazon2231
10.4.4 Android .................................233
10.5 ......................................................................................................234
2236
1........................................................................................................236
2........................................................................................................237
3........................................................................................................237
4........................................................................................................238
5........................................................................................................238
6........................................................................................................238
7........................................................................................................239
8........................................................................................................239
9........................................................................................................239
DB22242
.1 DB2..........................................................................................242
.2.1 DB2..........................................................................................243
.2.2 DB2 .........................................................................244
.3 DB2..............................................................................................245
.3.1 Windows...............................................................................245
.3.2 DB2 Linux............................................................................245
.4 DB2.........................................................................................246
.4.1 Control Center........................................................................................246
.4.2 Command Line..........................................................................247
.5 DB2..................................................................................249
.6 DB2.........................................................................................250
.7 . ...............................................................................251
.8 ...........................................................................................252
.9 DB2.....................................................................................253
. ....................................................................................................254
........................................................................................................255
14
Database Fundamentals
Database Fundamentals
.
SQL XML
.
Database Fundamentals
15
16
?
?
1
2 3 4
5, 6 7 SQL 8
XML SQL XQuery 9
10
A
()
db2univ@ca.ibm.com
"Database fundamentals book feedback"
SQL
NULL dir
SQL
SELECT flight
CREATE TABLE table_name
17
Textbooks **
Programming
Fundamentals
Cloud
Computing
IBM Data Studio
Database
Fundamentals
Software
Engineering &
Database
** Good for University/
College Courses
DB2
Express-C
DB2 App
Development
Ten steps to
career success
A career in
databases
**No software tought
Data
Warehouse
Eclipse
WAS CE
Java
pureQuery*
JNet
C/C++
Web 2.0
Open source
development
Career books **
InfoSphere
Data
Architect***
Adobe Flex
Ruby on Rails
PHP
SOA
Perl
Mobile App.
development
Python
Mac
Neeraj Sharma
Dynamic Warehousing Center of
Competency
Proof of
Concept (POC)
Liviu Perniu Automation Department at Transilvania University of Brasov
IBM 2006 Faculty Award Eclipse Innovation
Awards
Raul F. Chong DB2 on Campus IBM Toronto Laboratory
DB2 DB2 Raul
IBM 1997
DB2 IBM
DB2 Raul DB2 OS/390,
z/OS, Linux, UNIX DB2
DB2 Raul DB2
Understanding DB2 - Learning Visually with Examples 2nd Edition (ISBN-10:
0131580183) DB2 SQL PL Essential Guide
for DB2 UDB on Linux, UNIX, Windows, i5/OS, and z/OS (ISBN 0131477005)
DB2 on Campus
18
Agatha Colangelo
Data Modeler
Cuneyt Goksu
Marcus Graham
IBM US
Software developer
Amna Iqbal
Leon Katsnelson
Fraser McArthur
Technical Enablement
Specialist
Information Management Evangelist
10
5 7
10
7
19
Danna Nicholson
IBM US
Rulesh Rebello
IBM India
Suresh Sane
Database Architect
Nadim Sayed
Ramona Truta
University of Toronto
User-Centered Design
Specialist
Lecturer
SQL
1
Natasha Tolub
Susan Visser
10
1 -
1.1
(Relational database)
1 - 21
1.2
(DataBase Management System: DBMS)
(Database server)
(Interface)
1.2.1
.. 1960
mainframe
(Physical)
(Logical)
1.1
22
Self-describing data
Integration
Federation
Heterogeneous data
Extensibility
Distribution
Optimization
Data Dependence
Extending functionality
Scalability, parallellism
High performance
Logical Data Model
1.1
1.1
System R Codd
System R SQL/DS DB2
SQL
(Query)
DB2s optimizer
(Costbased)
DB2
1 - 23
SQL
.. 1970 SQL
SQL DB2
store procedure
DB2
Universal DB2 Universal Database (DB2 UDB)
Universal
DB2
(Data
Integration)
Cloud Computing
Cloud DB2 images Amazon EC2 Smart Business Development Cloud DB2
Cloud
Models)
(Real-world problem)
24
(Conceptual level)
1.1
Information Model
Data Model
Data Model
Data Model
Conceptual/Apstract Model
for designer and operator
Concrete/detailed model
for implementor
1.1
1.4
9
1 - 25
1971 1973
(record-at-a-time) 1.2
Next
Parent
Prior
Direct
Child
Parent
Prior
Next
Child
Prior
Next
Direct
Direct
Next
Next
Child
Prior
...
Child
1.2 -
CODASYL CODASYL
(child) (parent)
(root)
1.3
President
VP
Marketing
Social Media
Manager
VP
Finance
Direct Maketing
Manager
VP
Sales
Americas Sales
Manager
Asia Sales
Manager
1.3 -
.. 1968
26
IMS
IMS
Codd IMS
Codd 3
()
(set-at-a-time) (data manipulation language)
TIMETABLE
ENROLLMENT_NO
ATTENDENCE_RECORD
ENROLLMENT_NO [FK]
RESOURCE_ID [FK]
RESOURCE_ID
START_TIME [FK]
END_TIME
RESOURCE_ID
FACILITATOR_ID
TIMESTAMP
RESOURCES
SUBJECT_ID [FK]
FACILITATOR_MASTER
SUBJECT_ID
FACILITATOR_ID
FACILITATOR_NAME
TIMESTAMP
1.4
1 - 27
1.4.4
1970 Peter Chen
(1 to 1) (1 to
many) (many to many)
1.5
name
rec_num PK
lname
fname
bdate
anniv
email
child1
child2
child3
address
id_num PK
rec_num FK
street
city
state
zipcode
PK = Primary Key
FK = Foreign Key
Voice
vce_num PK
rec_num FK
vce-type
fax
fax_num PK
rec_num FK
oper_from
oper_till
modem
mdm_num PK
rec_num FK
b9600
b14400
b2800
1.5
1.5 name, address, voice, fax,
modem voice
vce_num rec_num vce-type PK FK
Chen
: IBM
28
1.4.6
(semi-
1.5
()
1 - 29
1.5.2 (Database Architect)
(Multi-tier Component Architecture)
(detailed designs)
(implementation details)
30
(Procedures)
(data dictionary)
SQL (Structure Query Language)
1 - 31
(Debug)
DB2 ( ) .NET
1.6
1.7
1. DB2 Express-C
DB2 ibm.com/db2/express
1.8
1.
2.
3.
4.
5. DBA
6.
A. pureXML
B.
C.
D.
E.
32
7. Optimization
A. (High availability)
B. (Security)
C. (Performance)
D. (Scalability)
E.
8.
A. (Distribution)
B. (Data Independence)
C. (Integration)
D. (Federation)
E.
9. pureXML
A.
B. (Extensibility)
C. (Optimization)
D.
E.
1 - 33
4 SQL
2.1
(Information Models)
(framework)
2 35
2.1
entity integrity
mantic constraints
union
intersection
difference
cartesian product
selection
projection
join
division
2.1
36
Information Models
The Hierarchical
Constraints
Entity
integrity
Data Model
Relation
Algeba
The Network
Relation
Calculas
The ObjectRelational
Data Model
Data Model
Referencial
integrity
Semantics
constraints
2.1
2.2
(candidate key) (primary key) (foreign
key)
2.2.1 (Attributes)
2 37
CARS Relations
Header
Body
TYPE
Attribute
PRODUCER MODEL
LIMOUSINE BMV
740
2008BLACK GAS
VAN
TRANSPORTER
2007RED
VW
Tuple
DIESEL
2008WHITE GAS
LIMOUSINE AUDI
ALLROAD
2009BLUE DIESEL
LIMOUSINE BMW
525
2007GREY DIESEL
Value
2.2 ()
2.2.2 (Domains)
(atomic value)
(value)
BMW Mercedes Audi VW Producer
dimension (
Color_Character
2.2.3 (Tuples)
2.2
38
(row)
2.2.4 (Relations)
[2.1]
2.2 CARS 6
(5 2.2
) 6
6 1 unary 2
binary 3 ternary n nary
(relation cardinality)
2.2 5
(relation instance)
4
()
()
Atomic
2.2.5 (Schemas)
3 (Concep-
2 39
2.2.6 (Keys)
(DBMS)
()
CAR SerialNumber ()
IdentificationNumber () 3
40
Candidate Keys
TYPE
PRODUCER MODEL
FABRICATION
YEAR
COLOR FUEL
SERIAL
NUMBER
IDENTIFI
CATION
NUMBER
LIMOUSINE BMV
740
2008BLACK GAS
WBADL9105
GW65796
SB24MEA
VAN
TRANSPORTER
2007RED
QASMD8209
NF37590
AB08DGF
2008WHITE GAS
XEFAR2096
WM19875
SB06GHX
SB52MAG
AB02AMR
VW
DIESEL
LIMOUSINE AUDI
ALLROAD
2009BLUE
DIESEL
AKLMD8064
MW79580
LIMOUSINE BMW
525
2007GREY
DIESEL
QMXAS4390
WQ21998
2.3 CARS
(unique key)
(DDL) UNIQUE
(DBMS) ()
2.2
ID ID
(surrogate key)
(artificial key) (surrogate key)
2 41
( 1)
2.2.6.3 (Foreign keys)
R2
R1 R1 R2
Primary key
TYPE
Foriegn key
PRODUCER MODEL
FABRICATION
YEAR
COLOR FUEL
SERIAL
NUMBER
IDENTIFI
CATION
NUMBER
LIMOUSINE BMV
740
2008BLACK GAS
WBADL9105
GW65796
SB24MEA
VAN
TRANSPORTER
2007RED
QASMD8209
NF37590
AB08DGF
VW
DIESEL
2008WHITE GAS
XEFAR2096
WM19875
SB06GHX
LIMOUSINE AUDI
ALLROAD
2009BLUE
DIESEL
AKLMD8064
MW79580
SB52MAG
LIMOUSINE BMW
525
2007GREY
DIESEL
QMXAS4390
WQ21998
AB02AMR
2.4 OWNERS
IdentificationNumber OWNERS IdentificationNumber
CARS
(Foreign-to-primary-key)
2.3
(integrity rules)
(constraint)
(schema level)
42
CAR
R2 FK PK R1 FK
R2 PK R1 ( FK )
t2 R2 t1 R1 t1
OWNERS IdentificationNumber
CARS
1. (Null Value)
2.
3
CASCADE cascades
()
RESTRICT restricted (
)
NULLIFIES
2 43
()
IdentificationNumber OWNERS
3. (update)
CASCADE cascades
()
identification
RESTRICT restricted
() identification number
CARS
NULLIFIES
()
IdentificationNumber IdentificationNumber
OWNERS
OWNERS
(domain constraint) (Null constraint)
(namely format)
(range)
44
IdentificationNumber XX99XXX
X 9
FabricationYear 1950 2010
2.3.3.2 (Null value)
FirstName LastName
CARS
SerialNumber
2
UNIQUE
SQL unknown
SQL
(Unknown)
SQL
A
A OR B
A AND B
A=B
True
True
True
True
True
True
False
True
False
False
True
True
True
Unknown
True
Unknown
Unknown
True
False
False
True
True
False
False
True
Unknown
False
False
False
False
False
False
Unknown
Unknown
False
False
Unknown
True
True
Unknown
Unknown
Unknown
False
Unknown
False
False
Unknown
Unknown
Unknown
Unknown
Unknown
2 45
(predicate)
20
CARS fabrication year (
) current year ()
CHECK
(trigger)
2.4
[2.3] 8 2 4
Codd
2.4.1 Union
Union 2 R1 UNION R2 t
R1 R2 union (union-compatible)
Union U
Union
2.5 Union R1 R2 R3
5
46
R1
R2
Name
Age
Sex
20
20
21
20
21
21
R3 = R1 U R2
Name
Age
Sex
20
21
21
20
21
2.5 UNION : R1 R2
2.4.2 Intersection
Intersection R1 INTERSECT R2
t R1 R2 intersect
intersect
2.6 INTERSECT R1 R2
R3 1
R1
R2
Name
Age
Sex
20
20
21
20
21
21
R3 = R1 R2
Name
Age
Sex
20
2.6 INTERSECT R1 R2
2.4.3 Difference
Difference R1 MINUS R2 R1
2 47
R2 difference
Difference
2.7 DIFFERENCE R1 R2
R3 2 R1 - R2 R2 - R1
R1
R2
Name
Age
Sex
20
20
21
20
21
21
R3 = R1 - R2
R3 = R2 - R1
Name
Age
Sex
21
21
Name
Age
Sex
20
21
2.7 DIFFERENCE R1 R2
t r R1 s R2 r =
(r1, r2, , rm) s = (sm+1, sm+2, , sm+n) t = (r1, r2, , rm, sm+1, sm+2, , sm+n)
R1 R2 ( union )
Cartesian product
R1 n N1 R2 m N2
R3 n-m N1*N2* 2.8
48
R1
R2
Name
Age
Sex
20
20
21
21
R3 = R1 X R2
Name
Age
Sex
Name
Age
Sex
20
20
21
20
20
21
21
21
2.4.5 Selection
select (subset)
select
<select condition> (<relation>)
<select condition>
<attribute> <comparison operator> <constant value>/<attribute>[AND/OR/NOT] <attribute> <comparison operator> <constant value>/<attribute>]
Selection
2.9 select R Age
2 49
R1= (Age=20)(R)
R
Name
Age
Sex
20
21
20
19
20
21
21
Name
Age
Sex
20
20
20
Age
Sex
20
21
2.4.6 Projection
Project
project
<attribute list> (<relation>)
<attribute list>
<attribute list>
Projection
2.10 project R 2
50
R
Name
Age
Sex
Name
Sex
20
21
20
19
20
21
21
Age
Sex
20
21
F
M
2.10 PROJECT ()
2.4.7 Join
Join (join condition or predi-
cate) 1
join join
join
R <join condition> S
<join condition>
<attribute from R> <comparison operator> < <attribute from S>
<, >, <=, >=, =, <>
Ai Bj join R
S join Ai Bj T t
r R s S join
join theta-join join
join
2 1
2 51
R1 LastName R2 R3
R1
R2
First
Name
Last
Name
Last Sex
Name
Mary
Ann
John
John
Ann
Mary
Bill
Last
Name
Mary
John
Ann
2.11 JOIN
2.12 join natural join R1 R2
right outer join
Natural Join
First
Name
Last Sex
Name
Mary
John
First
Name
Last Last
Sex
Name Name
Ann
Mary
Mary
John
John
Ann
Ann
NULL
NULL
Bill
52
2.4.8 Division
Division R1 (n + m)
R2 m n (n+i)
R1 i R2 division
R1 R2 R2
R1
2.13 Division R1 R2
R1
R1= R1 R2
Name
Sex
Name
Sex
R2
F
2.13 DIVISION
2.5
(Relational algebra)
2 53
RED CARS
(mathematical logic)
Codd
T
T t R
tuple variable
RANGE OF T IS X1; X2; ; Xn
T tuple variable X1; X2; ; Xn tuple calculus expressions
(Free
54
tuple calculus
QUEL INGRES tuple-oriented relational calculus
(membership conditions)
R (term, term, )
R term A:v A R v
(true) R
2 55
R (A:AX, B:BX, )
R A AX (
) B BX ()
Query-By-Example (QBE)
2.6
(alternate keys)
product
selection
projection
join
division
2.7
56
DEPARTMENTS
EMPLOYEES
DEPARTMENTS DeptNo DepName Manager Address Budget
DEPARTMENTS
DepNo
Numeric(2,0)
DepName Character(20)
Manager
Numeric(3,0)
Address
Character(50)
Budget
Numeric(10,2)
EMPLOYEES
ID
EmpName
Job
Salary
BirthDate
DepNo
Numeric(3,0)
Character(30)
Character(10)
Numeric(7,2)
Date
Numeric(2,0)
ID
(NOT NULL)
DB2
CREATE TABLE Departments (
DepNo Numeric(2,0) NOT NULL PRIMARY KEY,
DepName Char(20) NOT NULL,
Manager Numeric(3,0) NOT NULL,
Address Char(50),
Budget Numeric(10,2) );
CREATE TABLE Employees (
ID Numeric(3,0) NOT NULL PRIMARY KEY,
EmpName Char(30) NOT NULL,
Job Char(10) NOT NULL,
Salary Numeric(7,2),
BirthDate Date NOT NULL,
2 57
DepNo Numeric(2,0));
DEPARTMENTS EMPLOYEES 1 1
DepNo EMPLOYEES
DepNo DEPARTMENTS
DEPARTMENTS Relation
DepNo DepName
Manager Address
Budget
Software
211
Bucharest
2,000,000.00
Accounting 422
Bucharest
500,000.00
Hardware
Bucharest
4,000,000.00
Salary
BirthDate
DepNo
111
EMPLOYEES Relation
ID
EmpName
Job
211
Bucharest
04/05/1966
123
Bucharest
11/05/1975
311
Bill Johns
Bucharest
09/03/1980
Programmer
2.8
1. supplier 4 Id - supplier
(unique,not null) Name - Supplier (not null) Addess - supplier Discount - supplier 0%-50% ( not null, values
between 0 % and 50 %)
58
6.
A.
B. (atomic values)
C. (data characteristic)
D. (an ordered set of values that describe
data characteristics)
E.
6.
F.
G.
H. (atomic values)
I.
J.
7.
A. (domain)
B. (instance)
C. (value)
D. (degree)
E.
8.
A. (candidate)
B.
59
C.
D. (alternate key)
E.
9. (options)
A. Restrict
B. (Null)
C. Delete
D. Cascade
E.
(business rules)
(logical)
3.1
(Conceptual modeling)
(Conceptual
design)
( 4)
( 5)
(User requirement)
3 61
Requirement analysis
3.1 -
(information)
data
data information
3.2
62
Data
Input
Information system
Process/transformation
Output
Information
Feedback
3.2
3.2 (data)
(information)
3.2 ?
(abstraction)
3.2.1
Connolly [3]
3.2.2
(metadata)
(data description)
(Records-based Logical
Model)
(Object-based Logical Model)
3 63
(conceptual)
(Entity-Relationship model)
(Structural component)
(Manipulation component)
( )
3.2.3
(Entity-Relationship Diagram)
(Constraint)
M:N
(recursive relationships)
1 1
64
(Entity-Relationship model)
(Entity set)
(Attribute)
(Relationship set)
(Constraint)
(Domain)
(Extension)
(Intension)
3.2.3.2
Teacher, Student
Grade
Exam
3.3
Entities
Chess Set
Entity sets
Serving Folks
3.3 -
(TEACHER)
(STUDENT)
PERSON
TEACHER PROFES-
3 65
:
(tuples)
PERSON : NAME
ADDRESS PERSON=(NAME, ADDRESS)
3.2.3.3
()
(composite
attribute)
(single-valued attribute)
Title teacher
(multi-valued attribute)
(derived attribute)
(unstable attributes)
(stable attributes)
(mandatory attributes)
(Name)
66
:
InfoSphere Data Architecture required
Attributes properties
3.4 -
(optional attribute) -
(null value)
(unique identifier) -
(Student Id)
(Key)
(candidate key)
Minimal -
3 67
(alternate key)
- (surrogate key)
EMPLOYEE
3.5.
3.5 -
Simple Key
Composite Key
(Foreign Key)
3.2.3.4
(verb)
(
-recursive relationship)
: R
68
E1, E2 Ek R R(E1,
E2,, EK) R E1, E2 Ek R
3.2.3.5 (Constraints)
TEACHER
MENT
DEPART-
Cardinalities
R E () F (
) R
(1:1) - E F
(1:M) - E F
(M:M) - E F
1:M
3 69
Participation Cardinalities
Participation cardinalities
Total or mandatory
compulsory
Partial or Optional
non-compulsory
(Parent)
(Child)
(parent-
child relationship)
(hierarchical structure)
parent-child PERSON
70
PERSON
ID
FirstName
LastName
STUDENT
TEACHER
ID [FK]
ID [FK]
StartDate
Function
FinishDate
Salary
(hierarchy)
Principle
Assistant Principle
Teacher
3.8 -
recursive relationship
set
Teacher
3.9
(roles)
(Teacher) (Assistant principal)
3 71
TEACHER
manager of
TID
TID1 [FK]
Function
managed by
3.9 unary
: check eBook
Getting Started with InfoSphere Data Architect
eBook
3.10
STUDENT
is given
SID
SFirstName
SLastName
having
StartDate
FinishDate
3.10 -
GRADE
Course
SID
Grade
Class
72
3.2.3.6 (Domain)
CHECK SQL
CHECK
3.2.3.7 (Extension)
3.2.3.8 (Intension)
(schema)
3.3 - 1 3
1 -
()
3 73
books, authors, name, address, e-mail, loaner, client, borrowers, name, address, e-mail,
phone, loan date, return date, loan days, fine
dencies)
(depen-
LIBRARY,
Entity set
1
LIBRARY
BOOKS
AUTHORS
BORROWERS
CLIENTS
LOANERS
2 -
library
weak strong
weak
strong
No.
Entity set
Type
BOOK
Strong
AUTHOR
Strong
BORROWER
Strong
74
3 -
AUTHOR?
PHONE
Type
Domain
Optional
BORROWER_ID
Unique identifier
Text
No
NAME
Composite attribute
Text
No
Text
Yes
PHONE
Multi-valued attribute
Text
Yes
ADDRESS
Composite attribute
Text
Yes
BOOK_ID
Text
No
LOAN_DATE
Text
No
DUE_DATE
Derived attribute
Text
No
RETURN_DATE
Derived attribute
Text
No
Type
Domain
Optional
AUTHOR_ID
Unique identifier
Text
No
NAME
Composite attribute
Text
No
Text
Yes
PHONE
Multi-valued attribute
Text
Yes
ADDRESS
Composite attribute
Text
Yes
Type
Domain
Optional
BOOK_ID
Unique identifier
Text
No
TITLE
Text
No
EDITION
Numeric
Yes
YEAR
Numeric
Yes
PRICE
Numeric
Yes
ISBN
Text
Yes
3 75
PAGES
Numeric
Yes
AISLE
Text
Yes
DECRIPTION
Single attribute
Text
Yes
3.2.3.3 :
(Composite attribute)
(Multi-value attribute)
(Multi-value) (Single value)
DUE_DATE LOAN_DATE
10
DUE_DATE LOAN_DATE + 10
BORROWER entity set
Attribute name
Type
Domain
Optional
BORROWER_ID
Unique identifier
Text
No
FIRST_NAME
Text
No
LAST_NAME
Text
No
Text
Yes
PHONE
Text
Yes
ADDRESS
Composite attribute
Text
Yes
BOOK_ID
Text
No
LOAN_DATE
Text
No
RETURN_DATE
Text
No
Type
Domain
Optional
AUTHOR_ID
Unique identifier
Text
No
FIRST_NAME
Text
No
LAST_NAME
Text
No
Text
Yes
PHONE
Text
Yes
ADDRESS
Composite attribute
Text
Yes
76
Type
Domain
Optional
BOOK_ID
Unique identifier
Text
No
TITLE
Text
No
EDITION
Numeric
Yes
YEAR
Numeric
Yes
PRICE
Numeric
Yes
ISBN
Text
Yes
PAGES
Numeric
Yes
AISLE
Text
Yes
DECRIPTION
Text
Yes
4 (identifier)
BOOK_ID ISBN
5 -
(BOOK) (PERSON)
(BOOK) / (PERSON)
ally)
identifying non-identifying
(scenarios) :
Relationship set
1
2
3
BORROWER ->
BOOK
AUTHOR - >
BOOK
AUTHOR - >
BOOK
Identifying
Left
verb
No
Right verb
Cardinality
Borrows
Be borrowed
No
Write
Is written
No
Borrows
Be
borrowed
Many-tomany
Many-tomany
Many-tomany
Optionality
May
May
May
3 77
(many to many)
(decompose)
(one to many)
1. BORROWER -> BOOK
Type
Domain
Optional
COPY_ID
Unique identifier
Text
No
STATUS
Text
No
Type
Domain
Optional
ROLE
Text
No
:
Left
verb
Right verb
No
Has
No
Appear
No
Relationship set
Identifying
No
Borrows
Is created
Cardinality
Optionality
One-to-many
May
Is created
One-to-many
May
Has
One-to-many
May
Be borrowed
Many-tomany
Has
May
Relationship set
Identifying
Left verb
Right verb
Cardinality
Optionality
AUTHOR - >
BOOK
No
Borrows
Be borrowed
Many-to-many
May
AUTHORS BORROWERS
PERSONS
AUTHORS BORROWERS
PERSONS
78
( pedagogical
)
6 - (business rules)
:
0.1%
3.4
3 79
ER
InfoSphere Data Architect
3.5
(university):
Faculty
Teacher
Function
Course
Student
3.6
1.
A.
B.
C.
D.
E.
2.
A.
B.
C.
D.
E.
3. M:M
A. (optional) Many
B. (mandatory) One
80
C. Many
D. Many
E. (Recursive) One
4.
A.
B. (Conceptual model)
C.
D.
E.
5.
A.
B.
C.
D.
E.
6.
A.
B.
C. (should be read in double sense)
D.
E.
7.
A.
B.
C.
81
D.
E.
8.
A. Constraint
B. Cardinality
C. Superset
D. Subset
E.
9. SQL
A. Relationship
B. Primary Key
C. Check
D. Constraint
E.
10.
A. Intension
B. Extension
C. Schema
D. Instance
E.
4.1
4.1
4 83
STUDENT_ID
STUDENT
RANK
COLLEGE
COLLEGE_LEVEL
0001
Ria Sinha
Fergusson
0002
Vivek Kaul
15
PICT
0003
George Smith 9
IIT
0004
Will Brown
IIT
4.1.1
Record
COLLEGE_LEVEL
STUDENT_ID
STUDENT
0005
Susan Fuller
RANK
COLLEGE
10
Fergusson
COLLEGE_LEVEL
4.2
COLLEGE_LEVEL
4.1.2
Record (Row)
STUDENT_ID
STUDENT
RANK
COLLEGE
COLLEGE_LEVEL
0003
George Smith
IIT
0004
Will Brown
IIT
4.3
84
STUDENT
RANK
COLLEGE
COLLEGE_LEVEL
0001
Ria Sinha
Fergusson
0003
George Smith
Fergusson
4.4
4.2. (Decompositions)
(Shcema)
student
schema 4.1
STUDENT_ID
STUDENT
RANK
COLLEGE
COLLEGE_LEVEL
0001
Ria Sinha
Fergusson
0002
Vivek Kaul
15
PICT
0003
George Smith 9
IIT
0004
Will Brown
IIT
COLLEGE_LEVEL
STUDENT_ID
STUDENT
RANK
COLLEGE
Fergusson
0001
Ria Sinha
Fergusson
PICT
0002
Vivek Kaul
15
PICT
IIT
0003
George Smith 9
IIT
IIT
0004
Will Brown
IIT
4.1
4.1 student (a)
college student (b)
(c) COLLEGE_LEVEL (Record)
COLLEGE COLLEGE student
student relation COLLEGE
COLLEGE
COLLEGE_LEVEL
STUDENT_ID
STUDENT
RANK
4 85
college student
COLLEGE
COLLEGE_LEVEL
STUDENT_ID
STUDENT_ID
STUDENT
RANK
COLLEGE_LEVEL
(Schema)
Functional dependencies
A B R
AB B A functionally
FD A B
FD R r R
r FD
r FD AB (A B A B
)
Functional Dependency A B, B A A B
AB
A1 B1 , A2 B2, A3 B3 An Bn,
A1 A2 A3. An B1 B2 B3 Bn
R (A, B, C, D) AD
A
a1
b1
c1
d1
a2
b2
c2
d1
a3
b3
c3
d1
a4
b3
c4
d2
86
FDs 4.5 AD D A DA
D A (a1, b1,
c1, d1) (a2, b2, c2, d1)
STUDENT
RANK
COLLEGE
0001
Ria Sinha
Fergusson
0002
Vivek Kaul
15
PICT
0003
George Smith
IIT
0004
Will Brown
IIT
Functional
Dependencies
FD trivial
functional
dependency
A ()
non-trivial
FDs
trivial FDs
r FD, S clo-
4 87
Inference Rules 3
1. Reflexivity B subset A AB ( trivial FD )
2. Augmentation AB C ACBC reflexivity
ACB
3. Transitivity AB BC AC
axioms 3
closure FD FD
1. Union: AB AC ABC
2. Decomposition: ABC AB AC
Super key
Closure set A R
A FDs
: closure (A), A+ R
A Super key R
1. closure (A) = A
2. FD AB B closure (A), closure (A) U B
3. A, ( C A), AC ( trivial FD) CD
D A D closure (A)
4. 3 closure (A)
88
1 Closure (A) = A
2 AB, closure (A) = A U B AB
3
1st Iteration: BDE B closure (A), closure (A) = ABDE
2nd Iteration: ADC, D closure (A) C closure (A),
closure(A), A+ = ABDEC
Closure (C), C+ = C
Closure (D), D+= DC
Closure (E), E+= E
4.4.3 (Entailment)
Functional Dependencies (FDs)
functional dependencies
4 89
( row IDs , object IDs
timestamps )
Relatives of a family
candidate key
Movie_Title
Year
Type
Notting Hill
1999 Romantic
Lagaan
2000 Drama
Director
Director_DOB
Yr releases
Actors
cnt
Roger M
05/06/1956
30
Hugh G
Rhys I
Ashutosh G 15/02/1968
50
Aamir K
Gracy S
1NF
Actors
1NF Movie Table Cast Table 4.2
90
Movie_Title
Year
Type
Notting Hill
1999 Romantic
Lagaan
2000 Drama
Director
Director_DOB
Yr releases
cnt
Roger M
05/06/1956
30
Ashutosh G 15/02/1968
50
Movie Table
Movie_Title
Year
Actors
Notting Hill
1999 Hugh G
Notting Hill
1999 Rhys I
Lagaan
2000 Aamir K
Lagaan
2000 Gracy S
Cast Table
4.2 First Normal Form 1NF
4.2
1NF
Actors
4 91
Movie_Title
Year
Type
Notting Hill
1999 Romantic
Lagaan
2000 Drama
Director
Director_DOB
Roger M
05/06/1956
Ashutosh G 15/02/1968
Year
Notting Hill
1999 Hugh G
2000 50
Notting Hill
1999 Rhys I
Lagaan
2000 Aamir K
Lagaan
2000 Gracy S
Year
Yr releases cnt
1999 30
Actors
2NF
92
Movie_Title
Year
Type
Notting Hill
1999 Romantic
Lagaan
2000 Drama
Director
Director_DOB
Roger M
05/06/1956
Ashutosh G 15/02/1968
Director_DOB
Movie_Title
Year
Roger M
05/06/1956
Notting Hill
1999 Hugh G
Ashutosh G
15/02/1968
Notting Hill
1999 Rhys I
Lagaan
2000 Aamir K
Lagaan
2000 Gracy S
year_release_cnt
1999
30
2000
50
Actors
decomposition
3NF
4 93
Subject
Lecture_Day
Teacher
Graphics
Monday
Databases
Monday
Java
Wednesday
Dr. Prasad
Graphics
Tuesday
Java
Thursday
TeacherSubject
Teacher
Subject
Graphics
Dr.Arindham Singh
Graphics
Monday
Dr.Arindham Singh
Databases
Monday
Java
Dr.Prasad
Java
Wednesday Dr.Prasad
Java
Dr.George White
Graphics
Tuesday
Dr.Arindham Singh
Java
Thursday
Dr.George White
Teacher
4.9
BCNF
nontrivial
FD
4.6 Decompositions
Decomposition
relational schema
94
R
lossy
R functional dependency F R1 R2
lossless join
employee :
EMP_ID
EMP_NAME
WORK_EXP
DEPT_ID
DEPT_NAME
lossless decomposition :
DEPT_ID
DEPT_NAME EMP_NAME
EMP_ID
Department relation
EMP_NAME
WORK_EXP
Employee relation
DEPT_NAME
Department relation
EMP_ID
EMP_NAME
WORK_EXP
DEPT_ID
Employee relation
EMP_NAME
4.6.2 Dependency-Preserving
R relation X Y
FD relation R, F X FDs
C->D C D X Fx
relation R X Y
4 95
dency F+ R Fx U Fy F+ Fx FDs F+
X Fy FDs Y
constraints decomposed
Dependency
Dependency
F FDs
96
ABC,
BC,
AB,
ABC,
ACD
minimal cover Fc
:
1: FD RHS
(: XYZ XY XZ)
AB, AC,
BC,
AB,
ABC,
ACD
2: LHS BC ABC A
ABC BC FD AC ACD C
ACD AD
:
AB, AC,
BC,
AB,
BC,
AD
3: FDs
ABC B relation
AC,
:
AB,
BC,
AD
Minimal Cover Fc= {AB, BC, AD}
4 97
normalization 3NF
Dependency
4.5.3
3NF
Dependency
Book schema
3NF :
98
I_Type
I_Flavour
Amul
Scoop
Vanilla
Amul
Softy
Vanilla
Amul
Scoop
Chocolate
Amul
Softy
Chocolate
Baskin Robbins
Scoop
Chocolate
Baskin Robbins
Sundae
Chocolate
Baskin Robbins
Scoop
Strawberry
4 99
Baskin Robbins
Sundae
Strawberry
Baskin Robbins
Scoop
Butterscotch
Baskin Robbins
Sundae
Butterscotch
Vendor I_Flavour
update anomalies
I_Type
Vendor
I_Flavour
Amul
Scoop
Amul
Vanilla
Amul
Softy
Amul
Chocolate
Baskin Robbins
Scoop
Baskin Robbins
Chocolate
Baskin Robbins
Sundae
Baskin Robbins
Strawberry
Baskin Robbins
Butterscotch
4.11
fifth normal form [4.10], domain key normal form
100
Logical modeling
concept
Relation variable, R
Entity set
Relation
Entity
Tuple
Attribute
Relationship set
Unique identifier
4 101
BORROWER borrower
BORROWER BORROWER LOAN relations :
primary key
2nd normal form
3rd normal form
: Loan entity
foreign keys entity
InfoSphere Data Architect (IDA)
IDA final logical model:
102
AUTHOR
AUTHOR_ID
LASTNAME
FIRSTNAME
EMAIL
CITY
COUNTRY
BOOK
BOOK_ID
BORROWER
BROROWER_ID
TITLE
LASTNAME
EDITION
FIRSTNAME
YEAR
PRICE
PHONE
ISBN
ADDRESS
PAGES
CITY
AISLE
COUNTRY
DESCRIPTION
AUTHOR_LIST
AUTHOR_ID [FK]
BOOK_ID [FK]
ROLE
LOAN
COPY
COPY_ID [FK]
COPY_ID
BORROWER_ID [FK]
BOOK_ID [FK]
LOAN_DTAE
STATUS
RETURN_DATE
4.7
final logical model final logical model
1 conceptual model
specifying primary keys proceed normalize model
final logical model
3 5 3 logical
model physical model
4.13
model real-world objects
relational database
relate tables
relational database
relational schema
4 103
functional dependencies
relations
- lossless dependency
relational database
4.14
1.
Closure
2.
Order ( product_id, customer_id , price, quantity, order_type )
( product_id, customer_id ) order_type
4.15
104
2. Cell phone :
mobile
brand
head_office
N93
Nokia
New Delhi
Diamond
HTC
Hyderabad
N97
Nokia
New Delhi
MotoSlim
Motorola
Mumbai
3315
Nokia
New Delhi
ZN50
Motorola
Mumbai
E.
4. Functional
A. Closure set of functional dependencies, F+
B. Decomposition is lossless
C. X Y belongs to F+
D. Super key
E.
5 - SQL 105
A. MVDs
B. MVDs
C. Candidate key MVDs
D. Candidate keys
E.
6.
A. Lossless
B. Functional integrity constraints
C. Dependency preserving implies lossless join and vice-versa
D. BCNF
E.
5 - SQL
SQL
SQL SQL
SQL 3 :
SQL
SQL (Create)
(Read) (Update) (Delete) CRUD
5.1 SQL
1970s Don Chamberlin Ray Boyce SQL
System R
Codd
5 - SQL 107
SQL SEQUEL
(United Kingdom)
SQL
SQL
5.2 SQL
SQL
(data type)
UDT
address, country, phone number, social security number, postal zip code
5.2.1.1 (Date and Time)
(date and time)
DB2
Date (YYYY-MM-DD)
108
Time (HH:MM:SS)
Timestamp (YYYY-MM-DD-HH:MM:SS:ssssss)
ssssss (microseconds)
Year
Month
Day
Dayname
Hour
Minute
Second
Microsecond
5.2.2 (Create Table)
(Table) (Rows)
(Column)
(Entities)
SQL
myTable col1
NULL NULL
5.2.2.1 (Default Values)
Users ( Default)
Student
(DEPTNO)
5 - SQL 109
NULL
A UNIQUE UNIQUE
A PRIMARY KEY
UNIQUE
(unique indexes)
A REFERENTIAL referential
integrity
A CHECK
110
CHECK
CHECK PRIMARY KEY
4 (constrains)
PRIMARY KEY ID
nulls
10 100
HIREDATE 1986
SALARY 40500
ential integrity
(Primary Key) (Foreign Key)
referential
integrity
(de-
5 - SQL 111
(Syntax 1-3)
Syntax 1:
CREATE TABLE DEPENDANT_TABLE
(ID
INTEGER REFERENCES BASE_TABLE(UNIQUE_OR_PRIMARY_KEY),
NAME
VARCHAR(9),
:
:
:
);
Syntax 2:
CREATE TABLE DEPENDANT_TABLE
(ID
INTEGER,
NAME
VARCHAR(9),
:
:
:,
CONSTRAINT constraint_name FOREIGN KEY (ID)
REFERENCES BASE_TABLE(UNIQUE_OR_PRIMARY_KEY)
);
Syntax 3:
CREATE TABLE DEPENDANT_TABLE
(ID
INTEGER,
NAME
VARCHAR(9),
:
:
:
);
ALTER TABLE DEPENDANT_TABLE
ADD CONSTRAINT constraint_name FOREIGN KEY (ID)
REFERENCES BASE_TABLE(UNIQUE_OR_PRIMARY_KEY);
SQL (constraint name) DB2
15 CC1288717696656
2 (delete)
(update)
CASCADE
CASECADE
112
SET NULL
SET NULL
NULL
NO ACTION
NO
ACTION
RESTRICT
RESTRICT
5.2.3 (Schema)
DB2
(schema) (database objects)
DB2 2 1) 2)
john john
SCHEMA
set current schema = myschema
5 - SQL 113
5.2.4 (View)
(View)
Select
MYVIEW
CREATE VIEW MYVIEW AS
MYVIEW
MYVIEW select
SELECT * FROM MYVIEW
5.2.5
(CREATE
TABLE)
(Database Objects)
5.2.6
SQL ALTER
NULLs
SQL
ALTER ALTER
5.2.7
RENAME SQL
114
(table)
ALTER RENAME
ALTER TABLE <table name> RENAME COLUMN <column name> TO <new name>
5.3 SQL
5.3.1 (Select)
SQL (retrieve)
select
myTable
select * from myTable
* myTable
5.3.1.1 (Order)
select
select
DESC (decending)
5 - SQL 115
5.3.1.2 (Cursor)
(Cursor) select
select
FETCH
(loop)
(logic)
...
DECLARE p_sum INTEGER;
DECLARE p_sal INTEGER;
DECLARE c CURSOR FOR
SELECT SALARY FROM EMPLOYEE;
DECLARE SQLSTATE CHAR(5) DEFAULT 00000;
SET p_sum = 0;
OPEN c;
FETCH FROM c INTO p_sal;
WHILE(SQLSTATE = 00000) DO
SET p_sum = p_sum + p_sal;
FETCH FROM c INTO p_sal;
END WHILE;
CLOSE c;
...
FETCH
5.3.2 (Insert)
INSERT SQL
INSERT SELECT
myTable
insert into myTable values (1);
116
5.3.3 (Delete)
delete
where
5.3.4 (Update)
UPDATE
where UPDATE
where where
5 - SQL 117
select
2 SQL
1. (Inner Join)
2. (Outer Join)
SQL 3
Equi-join
Natural join
Cross join
5.4.1.1 Equi-join
Equi-join
SELECT *
FROM student, enrollment
WHERE student.enrollment_no=enrollment.enrollment_no
OR
SELECT *
FROM student
INNER JOIN enrollment
ON student.enrollment_no=enrollment.enrollment_no
student enrollment enrollment_no
5.4.1.2 Natural Join
Natural equi-join
DB2
118
Natural
Natural
SELECT *
FROM STUDENT
NATURAL JOIN ENROLLMENT
Natural
Natural Join
5.4.1.3 Cross Join
Cross
(Cartesian Product)
SELECT *
FROM SQL
(LEFT table) (RIGHT table)
Outer Join 3
5 - SQL 119
11111111
11221122
11331133
11111111
11221122
11331133
11111111
11221122
11331133
Student Table
Name
Year
Enrollment no
John Smith
11221122
Raul Chong
11331133
SubjectID
Enrollment no
Physics
100
11221122
Mathemethics
200
11111111
120
5.3.
SELECT *
FROM STUDENT
LEFT OUTER JOIN ENROLLMENT
ON STUDENT.ENROLLMENT_NO = ENROLLMENT_NO
Year
Enrollment no
Name
SubjectID
John Smith
11221122
Physics
100
Raul Chong
11331133
5.4.
SELECT *
FROM STUDENT
RIGHT OUTER JOIN ENROLLMENT
ON STUDENT.ENROLLMENT_NO = ENROLLMENT_NO
Right outer join
Name
Year
Enrollment no
Name
SubjectID
John Smith
11221122
Physics
100
11111111
Mathematics
200
5.5.
SELECT *
FROM STUDENT
FULL OUTER JOIN ENROLLMENT
ON STUDENT.ENROLLMENT_NO = ENROLLMENT_NO
5 - SQL 121
Year
Enrollment no
Name
SubjectID
John Smith
11221122
Physics
100
Raul Chong
11331133
11111111
Mathematics
200
Outer Join
(Business Requirement)
Left Outer Join
5.5.1 Union
Union
Union
5.6
SELECT * FROM student_table_a
UNION
Year
Enrollment no
John Smith
11221122
Raul Chong
11331133
Student Table B
Name
Year
Enrollment no
John Smith
11221122
Alan Doster
44556677
A Union B
Name
Year
Enrollment no
John Smith
11221122
Raul Chong
11331133
Alan Doster
44556677
5.6 - Union
5.6 Union
122
Year
Enrollment no
John Smith
11221122
Raul Chong
11331133
John Smith
11221122
Alan Doster
44556677
5.5.2 Intersection
intersaction
Year
Enrollment no
John Smith
11221122
5.8 INTERSECT
intersect
A B
A B INTERSECT ALL
5 - SQL 123
Alan Doster
Year
2
Enrollment no
44556677
5.9 EXCEPT
EXCEPT A B
A
EXCEPT ALL
select * from student_table_a
EXCEPT ALL
select * from student_table_b
+, -, * /
AND, OR NOT
CONCATENATE, LENGTH
SUBSTRING
124
5.6.2 Aggregation
Aggregation
Aggregation
5.6.3 HAVING
HAVING GROUP BY
HAVING
5
SELECT course_enrolled, count(*)
FROM students_enrollment
GROUP BY course_enrolled
HAVING count(*) < 5
WHERE WHERE
5 - SQL 125
5.7 (Sub-queries)
SQL
(Sub-query)
Inner Query
NULL
5.7.1
(Scalar)
SELECT name FROM students_enrollment
WHERE age = ( SELECT min(age) FROM students )
(min)
5.7.2
(Vector)
SQL
SQL
126
sub-query
final_result
max(marks)
FROM
FROM
Select
WHERE
5 - SQL 127
Name
Table name
Attribute
Column name
Method
Stored procedure
Constructor/Destructor
Triggers
Object identifier
Primary Key
5.1
(Object-relational mapping - ORM)
(object-oriented) (relational)
pureQuery
5.9 3
DB2
Physical modeling
concept
Relation variable, R
Table name
Entity set
Relation
Table
Entity
Tuple
Row
Attribute
Relationship set
Unique identifier
Primary key
Column
Primary key
128
(sub domain)
(constraint)
BORROWER
Attribute name
Domain
Sub-domain
Optional
Constraints
BORROWER_ID
Text
CHAR(5)
No
Pk_
FIRST_NAME
Text
VARCHAR(30)
No
LAST_NAME
Text
VARCHAR(30)
No
Text
VARCHAR(40)
Yes
PHONE
Text
VARCHAR(15)
Yes
ADDRESS
Text
VARCHAR(75)
Yes
CITY
Text
CHAR(3)
No
COUNTRY
Text
DATE
No
AUTHOR
Attribute name Domain
Sub-domain
Optional
Constraints
AUTHOR_ID
CHAR(5)
No
Pk_
Text
FIRST_NAME
Text
VARCHAR(30)
No
LAST_NAME
Text
VARCHAR(30)
No
Text
VARCHAR(40)
Yes
5 - SQL 129
PHONE
Text
VARCHAR(15)
Yes
ADDRESS
Text
VARCHAR(75)
Yes
CITY
Text
VARCHAR(40)
Yes
COUNTRY
Text
VARCHAR(40)
Yes
Sub-domain
Optional
Constraints
BOOK_ID
Text
CHAR(5)
No
Pk_
TITLE
Text
VARCHAR(40)
No
EDITION
Numeric
INTEGER
Yes
YEAR
Numeric
INTEGER
Yes
PRICE
Numeric
DECIMAL(7,2)
Yes
ISBN
Text
VARCHAR(20)
Yes
PAGES
Numeric
INTEGER
Yes
AISLE
Text
VARCHAR(10)
Yes
DECRIPTION
Text
VARCHAR(100) Yes
BOOK
LOAN
Attribute name
Domain
Sub-domain
Optional Constraints
BORROWER_ID
Text
CHAR(5)
No
Pk_, fk_
COPY_ID
Text
VARCHAR(30)
No
Pk_, fk_
LOAN_DATE
Text
DATE
No
< RETURN_DATE
RETURN_DATE
Text
DATE
No
130
COPY
Attribute name Domain
Sub-domain
Optional
Constraints
COPY_ID
Text
CHAR(5)
No
Pk_
BOOK_ID
Text
VARCHAR(30)
No
Fk_
STATUS
Text
VARCHAR(30)
No
Sub-domain
Optional
Constraints
AUTHOR_ID
Text
CHAR(5)
No
Pk_, fk_
BOOK_ID
Text
VARCHAR(30)
No
Pk_, fk_
ROLE
Text
VARCHAR(30)
No
AUTHOR_LIST
SQL
CREATE TABLE AUTHOR
(
AUTHOR_ID CHAR(5) CONSTRAINT AUTHOR_PK PRIMARY KEY(AUTHOR_ID)
NOT NULL,
EMAIL VARCHAR(40),
CITY VARCHAR(15),
COUNTRY CHAR(2)
)
CREATE TABLE AUTHOR_LIST
(
AUTHOR_ID CHAR(5) NOT NULL CONSTRAINT AUTHOR_LIST_AUTHOR_FK
FOREIGN
KEY(AUTHOR_ID) REFERENCES AUTHOR ( AUTHOR_ID),
BOOK_ID CHAR(5) NOT NULL,
ROLE VARCHAR(15) CONSTRAINT AUTHOR_LIST_PK PRIMARY KEY
(AUTHOR_ID,BOOK_ID) NOT NULL
5 - SQL 131
(
BOOK_ID CHAR(3) CONSTRAINT BOOK_PK PRIMARY KEY(BOOK_ID) CONSTRAINT AUTHOR_LIST_BOOK_FK FOREIGN KEY(BOOK_ID) REFERENCES
BOOK (BOOK_ID) NOT NULL,
EDITION INTEGER,
YEAR INTEGER,
ISBN VARCHAR(20),
PAGES INTEGER,
AISLE VARCHAR(10),
DESCRIPTION VARCHAR(100)
)
CREATE TABLE COPY
(
COPY_ID CHAR(5) CONSTRAINT COPY_PK PRIMARY KEY(COPY_ID) NOT
NULL,
BOOK_ID CHAR(5) CONSTRAINT COPY_BOOK_FK FOREIGN KEY(BOOK_ID)
REFERENCES
BOOK(BOOK_ID) NOT NULL,
STATUS VARCHAR(10)
(
COPY_ID CHAR(5) CONSTRAINT LOAN_COPY_FK FOREIGN KEY(COPY_ID)
REFERENCES
COPY(COPY_ID) NOT NULL,
BORROWER_ID CHAR(5) CONSTRAINT LOAN_BORROWER_FK FOREIGN
KEY(BORROWER_ID) REFERENCES BORROWER
(BORROWER_ID)
NOT
NULL,
132
(
KEY
EMAIL VARCHAR(40),
PHONE VARCHAR(15),
ADDRESS VARCHAR(60),
CITY VARCHAR(15),
COUNTRY CHAR(2)
SQL
DDL
5.10
SQL
SQL
/
SQL
SQL Reference Guide [5.3]
5.11
1.
(default value)
2. 10 SQL
3. SQL
4. SQL correlated sub-query GROUP BY
5. SQL (aggregate function) WHERE,
5 - SQL 133
HAVING
6. SQL ORDER BY
5.12
1. SQL
A. (Data definition)
B. (Data modification)
C. (Data control)
D.
E.
2. SQL
A. Raymond F. Boyce
B. E. F. Codd
C. Donald D. Chamberlin
D. A C
E.
3. SQL
A. American National Standards Institute
B. Bureau of International Standards
C. International Standards Organizations
D.
E.
4.
A. Name Table Name
B. Attribute Column name
C. Method Stored procedure
D.
E.
134
5.
A. Year
B. Dayname
C. Second
D.
E.
6. SQL
A. (Ascending)
B. (Descending)
C. (Random)
D.
E.
7. INSERT
A.
B.
8.
A. Equi-join
B. Natural-join
C. Cross-join
D.
E.
9.
A. Left outer join
B. Right outer join
135
10. Union
A.
B.
6 Stored Procedure
SQL
Stand-Alone ibm.com/db2/express
6.1 IBM Data Studio 2.2
138
6.3
6.3 DB2 for Linux, UNIX and Windows (DB2 LUW) Select a database
manager JDBC driver deault DB2 (LUW) JDBC
type 4 IBM Data Server Driver for JDBC and SQLJ (JDBC 4.0) Default
Host
IBM Data Studio DB2
localhost Host
Test Connection
Finish
Finish
Data Project Explorer +
PL/SQL packages, SQL scripts, Stored Procedures
Server
SQL #1
SQL #2
SQL #3
Network
myproc
SQL #1
CALL myproc
SQL #2
SQL #3
Stored Procedures
Stored Procedures
Stored Procedures
6.2.1 Procedures
Stored Procedures : SQL Procedures External Procedures SQL Procedures SQL External Procedures host language
SQL Procedures External Procedures Procedure (procedure definition) Procedure SQL Procedure External Procedure
Procedure
Procedure
Procedure SQL Procedure SQL
Procedure runtime options Procedure
Procedure
SQL Procedure
CREATE PROCEDURE UPDATESALARY
(IN EMPNUMBR CHAR(10),
(1)
(2)
140
IN RATE DECIMAL(6,2))
LANGUAGE SQL
UPDATE EMP
SET SALARY = SALARY * RATE
WHERE EMPNO = EMPNUMBR
(3)
(4)
(1)
(2)
(3)
(4)
142
= DB2/NT 9.7.0
= ARFCHONG
= SAMPLE
6.3
SQL
,
User-Defined Functions Functions Library
6.3.1
:
Scalar ()
- Aggregate ()
- String ()
Table ()
144
4 Mary
SQL SELECT-LIST
FROM
SELECT EMPNO, LASTNAME, YEAR(CURRENT DATE - BIRTHDATE)
FROM EMPLOYEE
WHERE WORKDEPT = D01
YEAR CURRENT
DATE BIRTHDATE
SQL
where clause (predicates) (query)
(Aggregate functions)
AVG(COL_NAME) COL_NAME
(Strings functions)
SUBSTR(abcdefghi,3,4)
(, , )
cdef
(Table functions)
FROM
INSERT, UPDATE
DELETE SQL DB2 SNAPSHOT_DYN_SQL()
MQREADALL() (Views)
(INSERT, UPDATE, DELETE)
6.3.2
Stored Procedure IBM Data Studio
User-Defined Function user-defined functions
Stored procedures Stored Procedure CREATE FUNCTION user-defined function (function template)
>>-CREATE--+-----------------+--FUNCTION--function-name-------------->
-OR REPLACE-
.-IN------.
>--(--+---------+--parameter-name--| data-type1 |--+-------------------+--|-)-->
|
|
-| default-clause |-
+-OUT----+
-INOUT---
-+-ROW-----+-----| column-list |-
--TABLE---
6.3.3
SQL
CALL SELECT VALUES REVERSE
SELECT reverse(col_name) from myschema.mytable
OR
VALUES reverse(abcd)
FROM SQL
TABLE() (alias)
146
SELECT * FROM
TABLE ( getEnumEmployee(E01)) T
TABLE () function
alias
6.7
6.3.4
user-defined function
1.
2. CREATE OR REPLACE FUNCTION CREATE FUNCTION
ALTER FUNCTION
FUNCTION
Function Function (fully qualified name)
DROP FUNCTION
DROP FUNCTION myschema.reverse
Function CREATE OR REPLACE FUNCTION Function
Function
Function CREATE OR REPLACE FUNCTION
6.4
Stored Procedures
Stored Procedures
EXECUTE Stored Procedure Stored Procedure
6.5
1. SQL PL Stored Procedure IBM Data Studio SAMPLE
DB2 procedure
EMPLOYEE
2. UDF (1)
3. SQL Function
( Monday, Tuesday )
4. SQL Function (
Monday, Tuesday )
5. procedure
6. procedure
6.6
1.
A. Select
B. Update
C. Count
D. Delete
E.
2.
A. avg
B. count
C. insert
D. substr
E.
3.
A. avg
B. count
C. max
D. substr
E.
4.
A. trim
B. upper
C. min
D. substr
E.
5.
A. lcase
B. year
C. max
D. substr
E.
148
6.
A. sum
B. min
C. max
D. len
E.
7.
A. avg
B. year
C. max
D. substr
E.
8. Stored Procedures Data Studio
A. SQL PL
B. PL/SQL
C. Java
D.
E.
9. VALUES
A.
B.
10. Procedure CALL
A.
B.
7 SQL
Structured Query Language (SQL)
,
SQL C,
C++, Java, .NET
Transaction
embedded SQL
static dynamicSQL
APIs ODBC, CLI JDBC
pureQuery
7.1 SQL
SQL
SQL
C, C++ Java
(functional logic)
Host Language SQL
SQL (embedded) host application
Application Programming Interface (API)
ODBC, CLI JDBC SQL
7.1
7 SQL 151
Application
SQLJ
IBM DB2 CLI
JDBC
Embeded SQL
7.1 SQL
7.2 Transaction ?
SQL
Transaction Transaction (unit of work)
insert, update delete
Transaction
1,000 A B
1,000 A
1,000 B
SQL SQL 2
2
Transaction SQL (Commit)
(Rollback) Transaction Transaction
152
SELECT
SQL
SQL (hard-code)
SQL (static embedded SQL application) SQL
where clause SQL
SQL
(host variables)
7.3.1.1 (Host variables)
static SQL
(default)
_hv
SQL C
7.1
EXEC SQL
SELECT emp_name, emp_dept, emp_salary
INTO :name_hv, :dept_hv, :salary_hv
FROM employee.details
7 SQL 153
7.1 SQL C
(DECLARE SECTION)
SQL
(commit) (rollback) SQL
7.2 SQL
C
int getDetails( int employee_id, double new_salary)
{
int ret_code = 1;
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION;
sqlint32 id_hv = 0;
// employee id
char name_hv[129] = {0};
// employee name
char dept_hv[129] = {0}; // employee department
double salary_hv = 0;
// employee salary
EXEC SQL END DECLARE SECTION;
// Copy the employee id and salary passed to this function
// into the host variables
id_hv = employee_id;
salary_hv = new_salary;
// Issue the UPDATE statement to set the new salary of an employee
EXEC SQL
UPDATE employee.details
SET emp_salary = :salary_hv WHERE emp_id = :id_hv;
if (SQLCODE < 0)
154
{
printf(\n UPDATE SQL Error:%ld\n,SQLCODE);
EXEC SQL ROLLBACK; // Rollback the transaction
ret_code = 0; // error
}
else
{
EXEC SQL COMMIT; // Commit the transaction
// Issue a SELECT to fetch updated salary information
EXEC SQL
SELECT emp_name, emp_dept, emp_salary
INTO :name_hv, :dept_hv, :salary_hv
FROM employee.details
WHERE emp_id = :id_hv;
if (SQLCODE < 0)
{
printf(\n SELECT SQL Error:%ld\n,SQLCODE);
Ret_code = 0;
}
else
{
// Display the updated salary information
printf(\n Employee name: %s,name_hv);
printf(\n Employee Id: %d,id_hv);
printf(\n Employee Department: %s,dept_hv);
printf(\n Employee New Salary: Rs. %ld p.a,salary_hv);
}
}
return ret_code;
int getDetails( int employee_id, double new_salary)
{
int ret_code = 1;
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION;
sqlint32 id_hv = 0;
// employee id
char name_hv[129] = {0};
// employee name
char dept_hv[129] = {0}; // employee department
double salary_hv = 0;
// employee salary
EXEC SQL END DECLARE SECTION;
7 SQL 155
156
fetch
2. (access plan)
SQL
optimizer
(system catalog)
SQL
SQL optimizer
SQL Static
(pre-compile)
SQL (bind)
SQL (link)
7 SQL 157
4
5
6
158
SQL Dynamic
(Interactive)
SQL 7.3 ,Employee finder tool
HR
V
Employee Name
Employee Id
RESULTS
Employee Name
Employee Id
Employee Designation
7 SQL 159
160
}
return ret_code;
7.3 SQL C SQL static
Dynamic
(Close cursor)
7 SQL 161
SQL ( SQLJ)
SQL static
SQL
2.
SQL
3.
SQL Static
SQL Dynamic
4.
SQL Static
rebinding
Dynamic SQL
(runtime), rebinding
162
API APIs
C, C++, Java
SQL
callable interfaces API
database connectivity driver
libraries libraries source code
API SQL
X/
(ISO/IEC 9075-3:1995 SQL/CLI)
CLI DB2
ODBC driver ODBC Driver Manager
7 SQL 163
DB2 CLI
Environment
Application
Application
ODBC Driver Manager
Other
ODBC
driver
Other
ODBC
driver
DBMS A
Gateway
B
DB2 CLI
dirver
DB2
ODBC
driver
Data Server
Client
Data Server
Client
DB2
Server
DB2 Connect
DBMS B
DB2
Server
DB2 Connect
DB2 (MVS)
SQL/DS
SQL400
other DRDS
DBMS
7.4.2 JDBC
JDBC Java Database Connectivity
// SQL for SELECT. The name, country, street and province information
// which has been provided by the user are stored in respective variables.
String sqlSel = select +name+, +country+, +street+, +province+, +zip+
from CUSTOMER where Customer = ?;
//prepare the SELECT statement
try {
PreparedStatement pstmt=con.prepareStatement(sqlSel);
164
}
} catch (SQLException e) {e.pringStackTrace ();
}
7.4 JDBC
SQL (sqlSel)
ResultSet result
7.5 pureQuery
Dynamic SQL
pureQuery SQL
Dynamic SQL
JDBC
7 SQL 165
//The name, country, street and province are variables which would be
//populated at runtime using user inputs.
String sqlSel = select +name+, +country+, +street+, +province+, +zip+
from CUSTOMER where Customer = ?;
Data data = DataFactory.getData (con);
//execute the Select and get the list of customer
List<Customer> customerList = data.queryList (sqlSel, Customer.class, custCountry);
7.5 pureQuery
pureQuery API queryList sqlSel
custCountry cutomerList
JDBC SQL (runtime)
JDBC
SQL API
pureQuery SQL string pureQuery annotation
@Select ( )
@Update ( SQL Data Manipulation Language: DML)
@Call ( SQL CALL)
SELECT
SELECT Name, Country, Street, Province, Zip FROM customer where Customer = ?
pureQuery
166
results
@Select(sql=select Name, Country, Street, Province, Zip from CUSTOMER where
Customer =?)
Customer getCustomer(int cid);
}
7.6 @Select
SQL Custom-
erData
pureQuery pureQuery
pureQuery generator
SQL
SQL
pureQuery Static
Dynamic
pureQuery :
http://publib.boulder.ibm.com/infocenter/idm/v2r2/index.jsp?topic=/com.ibm.datatools.
javatool.runtime.overview.doc/topics/helpindex_pq_sdf.html
JDBC Dynamic
7 SQL 167
SQL Static
pureQuery Client Optimizer
staticBinder
static
SQL Static
SQL SQL
pueryQueryXml
SQL Static
SQL SQL
Dynamic
7.6
SQL
transaction SQL
SQL
SQL
Dynamic
SQL Static
pureQuery
SQL Dynamic
(prepare)
168
7.7
A.
B.
C.
D.
Dynamic
Static
7.8
1. SQL Static
A. (runtime)
B. (pre-compile)
C.
D.
2. SQL
A. SQL
B. SQL
C.
D.
3. C C++ SQL
A. DB2 pre-compiler
B. DB2 pre-compiler
4. SQLJ
D. SQL
E. Call Level Interface SQL
5. ODBC
E.
G.
F.
H.
I.
6. Static Dynamic
A. JDBC
B. SQLJ
C. DB2 CLI
169
D.
E.
7.
A. JDBC
B. SQLJ
C. DB2 CLI
D.
E.
8. (?)
H. (runtime)
I.
J. SQL
K.
L.
9. pureQuery (annotated method)
I.
SQL Dynamic
J. SQL Static
K.
L.
10. pureQuery Client Optimizer
J. JDBC Static
K. JDBC Static
8 XML
(relational mod-
el)
XML (semi-structure)
XML
XML
DB2
XML (hybrid data server)
8.1 XML
XML eXtensible Markup Language XML (hi-
8 XML 171
XML element XML element root document element element (attribute) child element
XML element
<name>I am an XML element</name>
XML element
<employees>
<employee id=121>
<firstname>Jay</firstname>
<lastname>Kumar</lastname>
<job>Asst. manager</job>
<doj>2002-12-12</doj>
</employee>
</employees>
<employees> document element XML child ele-
172
in a parsed hierarchical
format
Relational columns
deptID
--
PR27
...
...
deptdoc
...
DB2 Storage
element
<product id=100-233-03 id=10023303/>
XML (XML schema definition)
element
child element
element
<xs:element name=employee>
<xs:complexType>
<xs:sequence>
<xs:element name=firstname type=xs:string/>
8 XML 173
8.1.3 Namespaces
XML namespaces
element
XML
XML
element
174
PRODUCTS (PRODUCT+)>
PRODUCT (NAME,PRICE,DESCRIPTION)>
NAME (#PCDATA)>
PRICE (#PCDATA)>
DESCRIPTION (#PCDATA)>
8 XML 175
<xsd:schema targetNamespace=http://www.mycompany/products
xmlns:xsd=http://www.w3.org/2001/XMLSchema>
<xsd:simpleType name=PriceType>
<xsd:restriction base=xsd:decimal>
<xsd:minInclusive value=0/>
XML Schema
<xsd:maxInclusive value=100000/>
Namespace
<xsd:totalDigits value=9/>
<xsd:fractionDigits value=3/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name=StockPriceType>
<xsd:sequence>
<xsd:element name=Asktype=PriceType/>
<xsd:element name=Bid type=PriceType/>
<xsd:element name=P50DayAvg type=PriceType/>
</xsd:sequence>
<xsd:complexType>
<xsd:element name=StockPrice type=StockPriceType/>
</xsd:schema>
8.2 XML Schema
XML Schema XML DTDs XML Schema
176
Orderschema
Namespace:
Order
Namespace:
Lineitem
Order.xsd
include
Lineitem.xsd
Parts.xsd
import
http://www.w3.org/TR/xmlschema-0/
8.3 - namespace namespace XML Schema
DB2 XML Schema
XML namespace
XML XML
integrity constraints
8 XML 177
Complex Types:
may include
elements/attribute
definition
Enumerations
etc.
anytime
...
myInteger
xs:integer -2 5
178
:
<xs:simpleType name= CapitalNames >
<xs:restriction base= xs:string >
<xs:pattern value = ([A-Z]( [a-z]*)?)+ />
</xs:restriction>
</xs:simpleType>
derivation by list derivation by
union derivation by list
<xs:simpleType name= myintegerList >
<xs:list itemType= xs:integer />
</xs:simpleType>
element
1 234 333 -32321 derivation by union
<xs:simpleType name= intordate >
<xs:union memberTypes= xs:integer xs:date />
</xs:simpleType>
element
223 1 2001-10-26
(integer date)
element element/
element (empty)
element (text)
<xs:complexType name=employeeType>
<xs:sequence>
<xs:element name=firstname type=xs:string/>
<xs:element name=lastname type=xs:string/>
</xs:sequence>
</xs:complexType>
element
<xs:element name=employee type=employeeType>
<xs:element name=employee>
<xs:complexType>
<xs:sequence>
<xs:element name=firstname type=xs:string/>
<xs:element name=lastname type=xs:string/>
</xs:sequence>
</xs:complexType>
8 XML 179
</xs:element>
element
DTDs element
element xs:unique
<xs:element name =book >
<xs:complexType>
.
</xs:complexType>
<xs:unique name=book>
<xs:selector xpath=book/>
<xs:field xpath=isbn/>
</xs:unique>
</xs:element>
ISBN XML
xs:key xs:keyref integrity constraints key unique constraint
element unique
<xs:element name =book >
<xs:complexType>
.
</xs:complexType>
<xs:key name=book>
<xs:selector xpath=book/>
<xs:field xpath=isbn/>
</xs:key>
</xs:element>
xs:keyref key (current scope)
element xs:keyref xs:key element xs:unique
element element element (ancestor)
XML Schema
180
XML Schema
DB2 pureXML:
schema XMLVALIDATE
schema
XML Schema
schema schema
8.3 XPath
XPath 2.0 expression language XQuery/XPath
8 XML 181
(item) atomic
values nodes
XQuery
(comma)
8.3.2 Document node
182
document
{
<customer-list>
{db2-fn:xmlcolumn(MYSCHEMA.CUSTOMER.INFO)/ns1:customerinfo/
name}
</customer-list>
}
XML (well-formed) node document
node
<products>
<product pid=100-201-01><description>
<name>Ice Scraper, Windshield 4 inch</name>
<price>3.99</price></description>
</product>
</products>
(/) (//)
step :
8 XML 183
context position
Description
Direction
Self
Forward
Child
Forward
descendant
descendant-or-self
Forward
Forward
Parent
Reverse
Attribute
Forward
node QName
Description
QName
NCName.*
*.NCName
Matches all nodes whose local name is equal to the specified NCName
184
Test
Description
node()
text()
comment()
processing-instruction()
element()
attribute()
Document-node()
abbreviated DB2
Abbreviated syntax
Description
No Axis specified
attribute::
//
/descedent-or-self::node() except when it appear in the beginning of path expression. In that case, axes step selects the
root of the tree plus all nodes that are its descendents
self::node()
..
Parent::node()
path expressions
Path expression
/dept/emp/firstname/child::node()
/dept/emp/firstname
/dept/emp//firstname/parent::node()/@id
/dept/emp/firstname/../@id
8 XML 185
XQuery db2-fn:xmlcolumn(PRODUCT.DESCRIPTION)/product/description/name
Execution result
1
-----------------------------------------------------<name>Snow Shovel, Basic 22 inch</name>
<name>Snow Shovel, Deluxe 24 inch</name>
<name>Snow Shovel, Super Deluxe 26 inch</name>
<name>Ice Scraper, Windshield 4 inch</name>
4 record(s) selected.
xmlcolumn XQuery string argument SCHEMANAME.TABLENAME.XMLCOLUMNNAME default schema
TABLENAME.XMLCOLUMNNAME Db2-fn namespace
xmlcolumn xmlcolumn XML
XML
umn sqlquery
XML
XML
8.4 XQuery
XQuery
XQuery XML
W3C
186
Owned by
XSLT WG
Owned by
Query WG
XML
SCHEMA
XQuery
Owned by
Schema WG
XSLT
XPath 2.0
Owned jointly by
Query and XSLT WGs
The W3C XML Query Working Group worked with the W3C XML Schema Working
Group and the W3C XSL Working Group to make a set of specifications that all
work together.
Use XQuery to take data from multiple databases, from XL files, from remote
Web documents even from CGI scripts, and to produce XML results that you can
process with XSLT.
www.w3.org/CML/Query/
8.6 - XQuery
8.4.1 XQuery
XQuery
prolog (declarations)
(query)
XQUERY
declare default element namespace http://posample.org;
for $cust in db2-fn:xmlcolumn(CUSTOMER.DESCRIPTION)
return $cust/Name/LastName;
(body) XQuery expression
8 XML 187
FLWOR
FOR LET
for ( $x)
$x 4 (sequence)
$p
188
1
----1
2
3
text node
DESCRIPTION PRODUCT
XML
XQuery
8 XML 189
<name>Ice Scraper, Windshield 4 inch</name>
1 record(s) selected.
190
</city>
<city>Toronto
<name>Kathy Smith</name>
<name>Matt Foreman</name>
<name>Larry Menard</name>
</city>
(aggregation) XQuery
element PurchaseOrder 2005 element
$po for path expression $po/item/
element item element PurchaseOrder nested expression(price * quantity) item fn:sum
item let fn:sum
$revenue
order by
</tr>
8.4.7 Quantification
Quantified expressions true false
(sequence)
some $i in (1 to 10) satisfies $i mod 7 eq 0
every $i in (1 to 5) , $j in (6, 10) satisfies $i < $j
Quntified expression quantifier some every quantifier
(sequence)
$i (1 to 10) $i $j
(1 to 5) (6 to 10) expression
expression
$i mod7 0
qualifier some
Quntified expression $i $j qualifier
every Quntified expression
8.5 XSLT
XSLT eXtensible Stylesheet Language Transformations
XSL XML XML
XML style sheets
HTML tag 8.7
XSLT
8 XML 191
XSL
Style
sheet 1
<dept bldg=101>
<employee id=901>
<name>John Doe</name>
<phone>408 555 1212</phone>
<office>344</office>
</employee>
</dept>
XSL
Style
sheet 2
XSL (FO)
Style
sheet 3
XML
2.
XSLT Stylesheet
192
<products>
<product pid=100-201-01>
<description>
<name>Ice Scraper, Windshield 4 inch</name>
<details>Basic Ice Scraper 4 inches wide, foam handle</details>
<price>3.99</price>
</description>
</product>
</products>
DB2 9.7 XslTransform XML XSLT stylesheet
( XML )
SELECT XslTransform HTML document
.html
SELECT XSLTRANSFORM (description USING stylesheet AS CLOB (10M)) FROM
product where pid like 100-201-01
:
1
---------------------------------------------------------<html>
<body>
<h2>Product Details</h2>
<table border=1>
<tr>
<th>Name</th><th>Price</th>
</tr>
</table>
</body>
</html>
1 record(s) selected.
8.6 SQL/XML
SQL / XML XML SQL SQL/XML
ANSI / ISO SQL based extensions ()
XML XML
SQL
XML XML XML schema
XMLCONCAT XMLAGG XML XML
8.6.1 XML Document
SQL / XML XML XML
(parse) (serialize) XML (Publishing)
XML web service
( XML )
XML web service XML
XML
business intelligence XML
8 XML 193
8.6.2 XML
(Publishing) SQL / XML
XML XML
194
Select
XMLELEMENT(NAME emp ,
XMLATTRIBUTES(EMPNO AS NUM,SALARY as salary ),
XMLELEMENT(NAME first , firstnme),
XMLELEMENT(NAME last, lastname) )
from employee
:
1
-----------------------------------------------------------
8.6.3.2 XMLQUERY
SQL / XML XQuery
XML XMLQUERY SQL
/ XML XMLQUERY XQueryexpression-constant (expression) XML SELECT
SELECT pid , XMLQUERY($DESCRIPTION/product/description/name
PRODUCTNAME FROM product
) AS
:
PID
PRODUCTNAME
-----------------------------------------------------------100-100-01 <name>Snow Shovel, Basic 22 inch</name>
100-101-01 <name>Snow Shovel, Deluxe 24 inch</name>
100-103-01 <name>Snow Shovel, Super Deluxe 26 inch</name>
100-201-01 <name>Ice Scraper, Windshield 4 inch</name>
4 record(s) selected.
DESCRIPTION XML
DESCRIPTION ( join )
PASSING
SELECT pid , XMLQUERY($D/product/description/name PASSING
prod.description as D ) AS PRODUCTNAME FROM product prod,
purchaseorder po
XML namespaces Query
8 XML 195
FROM product
) AS
:
PID
PRODUCTNAME
-------------------------------------------------------------------100-100-01 <name xmlns=http://posample.org>Snow Shovel, Basic 22 inch</
name>
100-101-01 <name xmlns=http://posample.org>Snow Shovel, Deluxe 24 inch</
name>
100-103-01 <name xmlns=http://posample.org>Snow Shovel, Super Deluxe 26
inch</name>
100-201-01 <name xmlns=http://posample.org>Ice Scraper, Windshield 4 inch</
name>
4 record(s) selected.
XMLQUERY XML sequence XML
predicate XMLEXISTS
XMLQUERY
SELECT PID 100-103-01
49.99
SELECT pid , XMLQUERY($DESCRIPTION/*:product/*:description/*:name ) AS
PRODUCTNAME FROM product
where
XMLEXISTS($DESCRIPTION/*:product[@pid=100-103-01]/*:description[*:pri
ce=49.99])
:
PID
PRODUCTNAME
-------------------------------------------------------------------100-103-01 <name xmlns=http://posample.org>Snow Shovel, Super Deluxe 26
inch</name>
1 record(s) selected.
XMLEXISTS XMLQUERY predicate
empty sequences XMLEXISTS (true false)
predicate XMLQUERY sequence XMLEXISTS empty sequence
SELECT predicate XMLEXISTS
SELECT predicate XQuery-expression-constant
XMLQUERY
SELECT pid , XMLQUERY(
$DESCRIPTION/*:product[@pid=100-103-01]/*:description[*:price=49.99]/*:n
ame)
AS PRODUCTNAME
FROM product
196
:
PID
PRODUCTNAME
----------------------------------------------------------------------100-100-01
100-101-01
100-103-01 <name xmlns=http://posample.org>Snow Shovel, Super Deluxe 26
inch</name>
100-201-01
4 record(s) selected.
3 empty sequences XMLQUERY sequence
sequence Predicate empty sequence Predicate XMLEXISTS XMLQUERY Predicate
8.6.3.3 XMLAGG
8 XML 197
8.7 XML
XML SQL / XML
XQuery XML XML
SELECT SQL XMLQUERY SQL /
XML XQuery
XML XQuery XMLQUERY
SQL SELECT XML
SELECT SQL XMLQUERY
8.8 XML
XML
DB2
XML native storage
DB2 XML XMLPARSE XMLSERIALIZE
XML text native XML native XML XML text
8.8.1 XMLPARSE
XMLPARSE XML
XML native XML ( hierarchical
tree format) insert DB2 default XML implicit
XML explicit XMLPARSE
INSERT XML
XML XML well-formed insert XML
198
8.8.2 XMLSERIALIZE
XMLSERIALIZE XML (
) CHAR /
CLOB / BLOB XML
(text) XQuery XML
XML SELECT XML DESCRIPTION
CLOB PID 10010001
SELECT XMLSERIALIZE(DESCRIPTION AS CLOB(5K)) FROM PRODUCT WHERE PID LIKE
10010001
:
1
-----------------------------------------------------------------------<product xmlns=http://posample.org pid=100-100-01>
<description><name>Snow Shovel, Basic 22 inch</name>
<details>Basic Snow Shovel, 22 inches wide, straight handle with D-Grip</
details><price>9.99</price><weight>1 kg</weight>
</description>
</product>
1 record(s) selected.
(properties)
TRANSFORM expression XML cid=
1000 TRANSFORM expression element
Type Home
XML :
<customerinfo>
<name>John Smith</name>
<addr country=Canada>
<street>Fourth</street>
<city>Calgary</city>
<state>Alberta</state>
<zipcode>M1T 2A9</zipcode>
</addr>
<phone type=work>963-289-4136</phone>
</customerinfo>
8 XML 199
update TRANSFORMexpression :
update customer
set info = xmlquery( copy $new := $INFO
modify (
do replace value of $new/customerinfo/phone with 416-123-4567,
do replace value of $new/customerinfo/phone/@type with home )
return $new)
where cid = 1000;
XML :
<customerinfo>
<name>John Smith</name>
<addr country=Canada>
<street>Fourth</street>
<city>Calgary</city>
<state>Alberta</state>
<zipcode>M1T 2A9</zipcode>
</addr>
<phone type=work>963-289-4136</phone>
</customerinfo>
8.9
XML XML
(semi-structured) XML
IBM DB2
XML ( XML Native ) XML
2 XQuery SQL/XM
L DB2 XML schema
(validate) XML XML schema TRANSFORM DB2
XML
8.10
1. (cid) XML
200
<city>Mumbai</city>
<zip>411202</zip>
</address>
</customer>
2. INSERT 5 XML XML
INSERT CID 10, 13, 15, 20, 23
3. SELECT XML
4. XQuery XML
5. XQuery XML XML cid 10 20
8.11
1. SQL / XML Publishing?
A. XMLELEMENT
B. XMLATTRIBUTE
C. XMLCONCAT
D. XMLPARSE
E.
2.
create table clients(
id
int primary key not null,
name
varchar(50),
status varchar(10),
contactinfo xml )
XML contactinfo
<customerinfo>
<name>Kathy Smith>
<addr country=Canada>
<city>Toronto</city>
<prov-state>Ontario</prov-state>
<zip>M5H-4C9</zip>
</addr>
</customerinfo>
<customerinfo>
<name>Amit Singh>
<addr country=Canada>
8 XML 201
<city>Markham</city>
<prov-state>Ontario</prov-state>
<zip>N9C-3T6</zip>
</addr>
</customerinfo>
Query ?
select xmlquery($c/customerinfo/addr/city[1]
passing info as c) \
from xmlcustomer \
where xmlexists($c/customerinfo/addr[prov-state=Ontario] \
passing xmlcustomer.info as c)
A. Toronto
Markham
B. <City>Toronto</City>
<City>Markham</City>
C. <City>Toronto
Markham</City>
D.
3. XML parsing
A.
(hierarchical format)
(relational
format)
202
E.
6. XQuery
xquery db2-fn:xmlcolumn(NNXML1.XMLCOL)/a/b
A. element b element element a XMLCOL
NNXML1
B. element a element root node b XMLCOL
NNXML1
C. element b element root node a XMLCOL
NNXML1
D. elementa XMLCOL NNXML1
7. XML DOC
Table description: CONTEST (DOC XML)
<dept bldg=111>
<employee id=901>
<name>Ajit Patil</name>
<phone>567 789 1342</phone>
<office>124</office>
</employee>
<employee id=922>
<name>Peter Jose</name>
<phone>121 768 3456</phone>
<office>213</office>
</employee>
</dept>
Query element <name>Peter Jose</name> ?
A. db2-fn:xmlcolumn(CONTEST.DOC)/dept/employee[@id=922]/name
B. select xmlquery($d/dept/employee[@id=922]/name passing DOC as d)
from contest
C. A B
D.
8. XQuery XQuery
xquery db2-fn:xmlcolumn(CONTEST.DOC)/dept/employee[@id=922]/name
A. xquery
db2-fn:xmlcolumn(CONTEST.DOC)
id=922]
B. xquery
name
db2-fn:xmlcolumn(CONTEST.DOC)
/dept/employee/name[../@
/dept/employee[../@id=922]/
203
D.
9. DB2 9.7 update XPath expression $new/
customer/phone phone element
update customer
set info =
xmlquery(copy $new := $information
modify do replace value of $new/customer/phone with 091-454-8654
return $new)
where cid = 67;
A. UPDATE
B. UPDATE phone element phone element
091-454-8654
C. UPDATE phone element phone element
091-454-8654
D.
9.1
9.1
9 205
Threats
Threats
Threats
9.1
:
(Privacy)
(Integrity)
(Availability)
(DBMS)
206
9.1.1
(secondary storage)
(backup)
9 207
(access control)
(view) (encryption) (integrity control)
(policy) (procedure)
(Hierarchy)
9.1.3
IBM DB2
DB2
(authentication) (authorization)
DB2
9.1.3.1 (Authentication)
DB2
DB2
Kerberos Lightweight Directory Access Protocol (LDAP)
208
procedure
(access control)
(DBMS)
(configuration files) DB2
authorization
ID (
Role)
( authorization ID)
(Group Role)
(Public Group) context-sensitive trusted context
role
DB2 implicit explicit explicit
role Grant implicit
DB2 3 (privilege)
Label-Based Access Control (LBAC) role
instance
(group) instance
instance (database manager configuration file)
DB2 instance 4
SYSADM (System administrator)
instance SYSADM
(migrate database) instance
transaction log
(Table Space) (Grant)
instance audit instance
9 209
instance
( DB2 version 9.7
DB2 9.7 DBADM DATAACCESS)
transaction log
(system catalog) log history files Reorganize
(runstats)
CONNECT
BINDADD
CREATETAB
CREATE_EXTERNAL_ROUTINE
procedure
9.1.3.4 (Priviledges)
(Priviledges) Role
9.2
DB2 [9.1]
210
Privileges
CREATETAB
CONTROL (Indexes)
IMPLICIT SCHEMA
CONTROL (Packages)
CONTROL (Tables)
CONTROL (IVoews)
Schema Owners
BIND
EXECUTE
ALL
ALTER
DELETE
INDEX
INSERT
REFERENCES
SELECT
UPDATE
ALL
DELETE
INSERT
SELECT
UPDATE
ALTERIN
CREATEIN
DROPIN
9.2 DB2
(Role) (PUBLIC)
PUBLIC PUBLIC
Public default CONNECT,
CREATETAB, BINDADD, IMPLICIT_SCHEMA, SELECT, UPDATE, EXECUTE, USE
CONTROL
9.1.3.5 Label Based Access Control
Label Based Access Control (LBAC)
mandatory access control (MAC) LBAC (row) (column) discretionary access control (DAC)
LBAC
(SECADM)
(security policy)
(security labels)
protected data
Grant
DB2
LBAC (system catalog)
LBAC SYSDBA, DBADM
SECADM
9 211
9.1.3.6 (Roles)
(Role)
(Role) (privilege)
(public)
GRANT (Developer role)
(insert) (update)
(end users)
(applications server authorization ID)
(end users)
Trusted Contexts (trusted relationship) DB2
DB2
(system authorization) (IP address)
(data stream encryption)
Trusted Contexts
(trusted connection)
2 explicit implicit explicit
(
)
(privilege) trusted context implicit
(privilege)
trusted context
:
(A system authorization ID)
IP (A list of IP addresses)
212
9.1.4 (Views)
union (base table)
(domain)
(User-defined data type) domain
domain constraint Check
constraint
Assertions constraint
Assertion
Assertions
Trigger
Trigger code
Trigger INSERT, UPDATE DELETE Trigger (event) (condition)
(action) Trigger
9.1.6
9.2
9.2.1
9 213
9.2.2
Mobile office
(GPS)
9.3
(access control)
(Discretionary control)
(Mandatory control)
DB2 (authentication) (authorization)
(privilege) (role) (LBAC) (trust context)
(view)
Check
constraint, Assertions Trigger
214
9.4
10 eBook Getting
started with DB2 Express-C 2
SYSCAT.TABLES ?
9.5
1.
2.
3.
4.
control)
(Discretionary
5. (Authorization) DB2
6. (Privileges)
7. (Trusted contexts) DB2
8.
9. (Integrity control)
10.
10 -
10
.. 2010 ..
2015
2,000
Cloud Computing
Cloud Computing,
Cloud
Cloud computing , ,
10.1
Cloud computing
10 - 217
Cloud computing
120 2
10.1.1 Cloud
Cloud computing 3 :
(Standardization)
(Virtualization)
(Automation)
Cloud
Cloud
Cloud Facebook, Yahoo, Gmail
218
IBM PaaS DB2, WebSphere Application Server
SaaS Salesforce.com
10.1.3 Cloud
Cloud Smart
Business Development and Test on the IBM Cloud, Amazon Amazon Web Services (AWS), Rackspace
10.1.3.1 IBM Smart Business Development and Test on the IBM Cloud
IBM Smart Business Development and Test on the IBM Cloud IBM developer cloud
Cloud
Intel 32- 64-
Linux RedHat SUSE Linux Microsoft Windows
IBM Developer Cloud https://www-147.ibm.com/cloud/enterprise 10.1 IBM Developer Cloud
10 - 219
10.3
SSH ssh
putty
220
10.3
Next
( DB2
Express-C )
10.1.3.2 Amazon
Amazon Web Services AWS Cloud AWS
:
IBM developer cloud AWS
Elastic Cloud compute (EC2) instances
Intel (32 64-) Windows Linux
10.4
AWS EC2 aws.amazon.com
10 - 221
Micro Instances
Micro Instance
32-bit or 64-bit
613MB of memory
2 ECUs
Standard Instances m1
Small Instance
Large Instance
32-bit,
64-bit,
1.7GB of memory
7.5GB of memory
1VC *1ECU = 1 ECU 2VC *2ECU = 4 ECUs
High-memory Instances m2
m2.xlarge
64-bit,
17.1GB of memory
2VC *3.25ECU = 6.5 ECUs
m2.2xlarge
64-bit,
34.2GB of memory
4VC *3.25ECU = 13 ECUs
Medium Instance
32-bit,
1.7GB of memory
2VC *2.5ECU = 5 ECUs
m2.4xlarge
64-bit,
68.4GB of memory
8VC *3.25ECU = 26 ECUs
VC = Virtual core
ECU = EC2 Compute Unit. 1 ECU ~ CPU capacity of 1.0 - 1.2 GHz 2007 or 2007 Xeon processsor
Instance storage -
10.1.4 Cloud
Cloud
Cloud Cloud
IBM Cloudburst IBM WebSphere Cloudburst Appliance
Cloud
Amazon Cloud
Internet
222
10.1.5 Cloud
Cloud
IBM DB2 Cloud
DB2 AWS IBM
developer cloud DB2 cloud VMware WebSphere Cloudburst appliance 10.5 DB2 (private cloud)
(hybrid cloud) (public cloud)
Hybrid
Public
Developer Cloud
DB2 Enterprise Developer Edition
(pay)
DB2 Express-C (free)
Amazon:
DB2 AMIs
DB2 Templates on RightScale.com
Industry AMIs (include DB2)
DB2 Ubuntu AMIs by Canonical
10 - 223
(
) Cloud
Cloud
DR site Cloud
ssh HADR
Cloud Cloud
HADR 15
DB2
Cloud Cloud DB2
DB2
10.2
Cloud
Mobile Applications
Mobile Application development platform
Mobile device platform
(Embedded OS, and mobile device)
10.6
10.6
Mobile device platform
Microsoft Windows Mobile 5.0
Dell AXIM X51v
Mobile application development platform
, APIs Mobile
application development platform Mobile device platform
Windows Mobile 6.0 Microsoft Visual Studio 2005/2008 Windows Mobile 6.0
SDK
Mobile device platforms mobile application development platforms
:
224
10.2.1
()
SDK
10.2 SDKs,
Operating System Language/OS op- SDKs/Tools
Developer Web Site
(OS)
tions
Symbian OS
Carbide C++,
Java, C++
Windows Mobile
developer.symbian.com
device
Developer Center
Objective-C
Xcode
www.apple.com/iphone
Android
Java
Eclipse, Android
www.android.com
Palm OS
C, C++, Java
EveryPlace Micro
Environment, Palm
Windows Mobile
10.2 SDKs
10 - 225
10.2.2
?
Java, .NET (C#,
VB), C, C++
/
Java
Java Java
10.2.3
226
Android Java
Android Java Java
SDK , ,
( QEMU), ,
x86 Linux ( Linux ), Max
OS X 10.4.8 , Windows XP Vista Java
Development Kit, Apache Ant Python 2.2
Eclipse (3.2 ) Android Development Tools (ADT)
Java XML
, Android
10.2.4
10.2.5
PDA
3G
10 - 227
Telematics, m-Commerce m-Enterprise, Mobile Multimedia Streaming, Mobile Messaging, Location
Based Mobile Computing
10.2.6 DB2
DB2 DB2 Everyplace DB2 Everyplace
:
Getting started with mobile application development,
DB2
business intelligence
IBM Cognos
IBM Smart Analytics System
Business Intelligence
: business intelligence
Getting started with data warehousing, DB2
db2university.com
10.7 db2university
228
10.7 db2university.com
10.4.1 Moodle
db2university.com Moodle (CMS)
Moodle PHP CMS
Martin Dougiamas Curtin University of Technology
Perth .. 2001
52,000 950,000 175
moodle.org
Moodle .. 2009 California
State University, Long Beach (CSULB)
Moodle 1.9.6 DB2 Express-C (
patch) http://moodle.org/mod/data/view.php?d=13&rid=3100&filter=1
.. 2010 Moodle 2.0 DB2 Express-C Moodle 2.0
Moodle 2.0 Release Candidate 1 DB2 Express-C
db2univertsity.com 2.0
db2university.com Moodle
10.8 db2university.com
Learn Learn
db2university
10 - 229
10.8 db2university.com
db2university.com DB2
PHP Ruby on Rails
DB2
:
Paypal Moodle
10.9 10.10 DB2 Essential Training I Moodle : ,
transcripts ( PDF )
230
10.4.2 openID
db2university.com openID
Facebook, Google, Yahoo, AOL, ChannelDB2
db2university
10.11
10 - 231
10.11 openID
Sign in with OpenID
ChannelDB2
/
db2university.
com
IBM developerWorks openID
EBS 50 GB
S3 buckets 3 1 GB
CloudFront
EC2 Moodle
DB2 (DB2 HADR )
DB2 HADR
S3 EBS 10.12
232
EBS
DB2 config
EBS
DB2 data
& Logs
S3 EBS volume
snapshots S3
AWS CloudFront
edge
S3 bucket edge
10 - 233
10.4.4 Android
Moodle
Android App Inventor
10.13
Moodle
App Inventor
( Web Service Ruby/Sinatra) IBM developerWorks
234
10.5
.. 2015
Cloud
business intelligence
business
intelligence IBM Smart Analytics
db2university.com
235
1.
2. DBMS
3.
4. (Data Inpendence) (
)
5. (DBMS)
6. A. pureXML
7. C.
8. E.
9. D.
237
2
1.
2. Intersection:
R1 R2 = R1-(R1-R2).
3
1. D.
2. A.
3. C.
4. A.
5. B.
6. D.
7. B.
8. D.
9. C.
10. B.
238
4
1. 4.6.1 Lossless Lossy Decompositions
2. C.
3. B.
4. E.
5. B.
6. C.
5
1. D.
2. D.
3. A, C.
4. D.
5. D.
6. A.
7. B.
8. D.
9. D.
10. B.
6
1. C.
2. C.
3. E.
4. C.
5. C.
6. D.
7. D.
8. D.
9. A.
10. A.
239
7
1. B.
2. A.
3. B.
4. A.
5. B.
6. B.
7. B.
8. A.
9. B.
10. B.
8
1. D.
2. B.
3. B.
4. D.
5. A.
6. A.
7. C.
8. A.
9. A.
9
1.
2. ,
:
3. :
4. Discretionary Control
5. DB2 3 :
Label-Based Access Control (LBAC)
240
6.
8.
9.
,
10.
241
DB2
DB2
DB2
:
DB2
DB2
DB2
DB2
DB2
DB2
:
DB2 (free e-book) Getting Started with DB2 Express-C
.1 DB2
DB2
DB2 XQuery SQL DB2
.1 DB2 Getting Started
with DB2 Express-C e-book.
DB2 243
Command Editor
Command Line Processor
Command Window
create bufferpool
create tablespace
create table
alter buferpool
alter tablespace
alter table
select
insert
update
delete
...
Information
Information Center
Check for DB2 Updates
Monitoring Tools
...
DB2 CLP Commands
db2
update dbm cfg
catalog db
list tablespaces
...
<sql statement>
xquery<
DB2 Tools
>
Event Analyzer
Health Center
Indoubt Transaction
Manager
Memory Visualizer
Activity Monitor
Setup Tools
Configuration Assistant
Configure DB2 .Net Data
Provider
First Steps
Default DB2 Selection Wizard
DB2 Environment
Instance 'myinst'
Database Manager
Configuration
Configuration
Port
Development Tools
IBM Data Studio
Optim Development Studio
.1 DB2
.1 DB2 SQL
DB2
.2 DB2
DB2 , DB2
DB2 DB2
.2.1 DB2
.2 DB2
244
DB2 Express-C
Extra
functionality
Extra
functionality
Extra
functionality
.2 DB2
.2 DB2 DB2 Express-C DB2 DB2
DB2 Express-C DB2 Express DB2 Express
DB2 Workgroup .2 DB2
DB2 Express-C DB2 DB2
DB2 Express-C.
DB2 Express-C DB2
.2.2 DB2
DB2 DB2 DB2
IBM Data Server Client IBM Data Server Runtime
Client .3
IBM Data Server Client
IBM Data Server Runtime Client
Drivers & Network
Supprt
Gui Tools
.3 DB2
.3 IBM Data Server Runtime Client (
) DB2 IBM Data Server Client
IBM Data Server Runtime Client
GUI
DB2 :
DB2 245
DB2 Runtime Client Merge Modules for Windows: DB2 runtime client Windows
IBM Data Server Driver for JDBC and SQLJ: Java
DB2
IBM Data Server Driver for ODBC and CLI: ODBC CLI
DB2
IBM Data Server Driver Package: .NET
ODBC, CLI open source IBM Data Server Driver
ODBC, CLI NET
IBM DB2 DB2
.3 DB2
DB2 DB2
.3.1 Windows
DB2 Windows :
1. (user) (Administrator Group) DB2
2. unzip DB2 Express-C Windows ibm.com/db2/express
setup.exe
3.
4. :
DB2 C:\Program Files\IBM\SQLLIB
Windows DB2USERS DB2ADMNS
DB2 C:\Program Files\IBM\SQLLIB\DB2
DB2 Administration Server (DAS)
:
My Documents\DB2LOG\db2.log
My Documents\DB2LOG\db2wi.log
Windows Services
246
- DB2 /opt/ibm/db2/V9.7
- :
db2inst1 ()
db2fenc1 ( fenced )
dasusr1 ( DAS )
- :
db2iadm1
db2fadm1
dasadm1
- db2inst1
- dasusr1
- :
/tmp/db2setup.his
/tmp/db2setup.log
/tmp/db2setup.err
.4 DB2
DB2 DB2 Control Center, DB2 Command
Editor DB2 9.7
IBM Data Studio IBM Data Studio
DB2 Ebook Getting started with IBM Data
Studio for DB2
DB2 9.7 DB2 Control Center
.4 DB2
DB2 247
Control Center Windows start - > Programs - > IBM DB2
- > DB2COPY1(Default) - > General Administration Tools - > Control Center
db2cc Windows Command Prompt or Linux shell Control Center
:
DB2
( .5)
SAMPLE
Command Line :
DB2 Command Window ( Windows)
DB2 Command Line Processor (DB2 CLP)
DB2 Command Editor (GUI-based, )
.5 DB2
248
DB2 Command Window
DB2 CLP DB2 Command Window
db2 :
db2 connect to sample
DB2 249
.5 DB2
.8 DB2
DB2 Express-C Server
Environment Variables
Instance 'myinst'
Database Manager
Configuration
Configuration
.8 DB2
Port
250
.8 DB2 Express-C
(Environment Variables, Database Manager Configuration File, Database Configuration File, DB2 Profile Registry ) DB2
myinst
.1
GUI DB2
db2start
db2stop
db2icrt <instance_name>
db2idrop <instance_name>
db2ilist
.1 DB2
.8 MYDB1
myinst .2
/SQL
connect to <database_name>
SQL
.2 SQL
.6 DB2
DB2 Configuration Advisor GUI
tool Control Center
Configuration Advisor
DB2 251
dbm cfg)
.3 dbm cfg
dbm cfg
dbm cfg
.3 dbm cfg
(Database Configuration File db cfg)
.4
db cfg
db cfg
db cfg
.4 db cfg
DB2 (DB2 Profile Registry variables)
() (
) .5 DB2
db2set -all
DB2 profile
registry
.7
()
(Catalog DB)
connect to database_name
Configuration Assistant GUI tool :
1. Configuration Assistant db2ca Windows command
prompt Linux shell .9 Configuration Assistant GUI tool
252
4.
Manually configure a connection to a database TCP/IP
(IP Address) DB2 service name
.
5.
6.
Test Connection
.8
DB2
ftp://ftp.software.ibm.com/software/data/db2/udb/db2express/samples.zip
CLI
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0401chong/index.html#scenario1
ODBC
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0401chong/index.html#scenario2
DB2 253
C SQL
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0401chong/index.html#scenario3
JDBC Type 2 Universal (JCC)
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0401chong/index.html#scenario6
JDBC Type 4 Universal (JCC)
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0401chong/index.html#scenario8
Visual Basic c ++ ADO - IBM OLE DB provider DB2 (IBMDADB2)
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0402chong2/index.html#scenario1
Visual Basic c ++ ADO - Microsoft OLE DB Provider ODBC (MSDASQL)
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0402chong2/index.html#scenario2
Visual Basic C# ADO .NET IBM DB2 .NET Data Provider
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0402chong2/index.html#scenario3
Visual Basic C# ADO .NET Microsoft OLE DB .NET Data Provider
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0402chong2/index.html#scenario4
Visual Basic C# ADO .NET Microsoft ODBC .NET Data Provider
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0402chong2/index.html#scenario5
.9 DB2
DB2 Information Center DB2
DB2 Information Center http://publib.boulder.ibm.com/infocenter/db2luw/
v9r7/index.jsp DB2 Information Center
http://www.ibm.com/software/data/db2/9/download.htmlS_TACT=download & S_CMP =
expcsite
1. DB2 Express-C
ibm.com/db2/express
DB2 Express-C. DB2 Express-C
254
http://www-01.ibm.com/software/data/optim/data-architect/
[1.1] CODD, E.F. A relational model of data for large shared data banks, CACM 13, NO
6, 1970
[2.1] DATE, C.J. An introduction to database systems, Addison-Wesley Publishing Company, 1986
[2.2] MITEA, A.C. Relational and object-oriented databases, Lucian Blaga University
Publishing Company, 2002
[2.3] CODD, E.F. Relational completeness on data base sublanguage, Data Base Systems, Courant Computer Science Symposia Series, Vol.6 Englewood Cliffs, N.J, PrenticeHall, 1972
[2.4] KUHNS, J.L. Answering questions by computer: A logical study, Report RM-5428PR, Rand Corporation, Santa Monica, California, 1967
[2.5] CODD, E.F. A data base sublanguage founded on the relational calculus, Proceedings ACM SIGFIDET Workshop on Data Description, Access and Control, 1971
[2.6] LACROIX, M., PIROTTE, A. Domain oriented relational languages, Proceedings 3rd
International Conference on Very Large Data Bases, 1977
[2.7]LACROIX, M., PIROTTE, A. Architecture and models in data base management systems, G.M. Nijssen Publishing company, North-Holland, 1977
[3.1] IBM Rational Data Architect Evaluation Guide
[3.2] Connolly, T., Begg, C., Strachan, A. Database Systems A Practical Approach
to Design, Implementation and Management, Addison Wesley Longman Limited 1995,
1998
[3.3] IBM InfoSphere Data Architect Information Center
[3.4] http://www.ibm.com/developerworks/data/bestpractices/
[3.5] 03_dev475_ex_workbook_main.pdf, IBM Rational Software, Section 1: Course
Registration Requirements, Copyright IBM Corp. 2004
[4.1] Codd, E. F. The Relational Model for Database Management
[4.2] Codd, E.F. Further Normalization of the Data Base Relational Model.
[4.3] Date, C. J. What First Normal Form Really Means
[4.4] Silberschatz, Korth, Sudershan - Database System Concepts
[4.5] William Kent - A Simple Guide to Five Normal Forms in Relational Database Theory
[4.6] Raghu Ramakrishnan, Johannes Gehrke - Database management systems
[4.7] Vincent, M.W. and B. Srinivasan. A Note on Relation Schemes Which Are in 3NF
But Not in BCNF.
[4.8] C. J Date : An Introduction to Database Systems 8th Edition
DB2 255
[4.9] William Kent: A simple guide to five normal forms in relational database theory
http://www.bkent.net/Doc/simple5.htm
[4.10] Ronald Fagin, C J Date: Simple conditions for guaranteeing higher normal forms
in relational databases
http://portal.acm.org/citation.cfm?id=132274
[4.11] Ronald Fagin: A Normal Form for Relational Databases That Is Based on Domains
and Keys
http://www.almaden.ibm.com/cs/people/fagin/tods81.pdf
[4.12] C. J. Date, Hugh Darwen, Nikos A. Lorentzos: Temporal data and the relational
model p172
[4.13] C J Date: Logic and databases, Appendix C
[5.1] Differences between SQL procedures and External procedures
http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/topic/com.ibm.db29.doc.
apsg/db2z_differencesqlprocexternalproc.htm
[5.2] SQL Reference Guide
http://www.ibm.com/developerworks/data/library/techarticle/0206sqlref/0206sqlr
ef.html
[6.1] http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/topic/com.ibm.db29.
doc.apsg/db2z_differencesqlprocexternalproc.htm
IBM DB2 DB2 Express-C DB2
SQL XML
:
ibm.com/developerworks/data/
DB2 Express-C :
ibm.com/db2/express
:
channelDB2.com
DB2 on Campus ebook db2university.
com
256
Rattasit Sukhahuta
8
rattasit.s@cmu.ac.th
8
( 2539 - )
( 2548
-)
Bachelor Degree in Computer Science
University of Hawaii at Hilo, Hawaii, USA, 1995
Master Degree in Information Systems
Hawaii Pacific University, Hawaii, USA, 1996
Doctor of Philosophy
University of East Anglia, Norwich, United Kingdom, 2001
257
Information Management
DB2 Express-C
PureXML
XML
www.ibm.com/software/data/db2/express