Top Banner
© IBM Corporation
278
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

IBM Corporation

Unit01 : DB2 Client Cli t DB2 Unit02 :

Unit03 : DB2 DB2 DB2 DB2 Unit04 U it04 : Command Line DB2

Unit05 : DB2 DB2 DB2

IBM Corporation

Unit06 :

DB2 Unit07:

DB2 Unit08 : ,

DB2 9.5 PL/SQL Unit09 : Security Role DB2 SQLPL

IBM Corporation

Unit10 : Export / Import/LOAD DB2 Export / IMPORT / LOAD

Unit11 : DB2 DB2 DB2 Unit12 : Trace DB2 DB2 DB2 DB2 DB2 db2pd

IBM Corporation

IBM Corporation

Point

DB2

.

Platform

.

Oracle Enterprise Edition 11g Windows, Linux, AIX, HP-UX, HP Compaq, Solaris, Tru64 CPU RAM CPU .

DB2 Enterprise Server Edition V9.7 (ESE) Windows, Linux, AIX, HP-UX, Solaris, Linux/390 CPU . ,

, Automatic Workload Management

.

High Availability Workload Management Table Partitioning Feature .

Standard Edition(SE) / Standard Edition One(SE1) 11g a da d d o O ( ) g Windows, Linux, AIX, HP-UX, HP Compaq, Solaris, Tru64 CPU RAM DataSize SE SE1 SE SE1 Oracle RAC 4 CPU 2 CPU . . . 500GB . .

DB2 Workgroup Server Edition V9.7 (WSE) Windows, Linux, AIX, HP-UX, Solaris, Linux/390

4 CPU

16GB

.

. High Availability .

Oracle Express Edition(XE) 11g Windows, Linux CPU RAM DataSize

DB2 Express Edition / DB2 Express-C V9.7 (EXP) Windows, Linux

1 CPU

1GB

.

2 CPU

4GB

.

4GB / /

. CPU . , DB2 Express-C PL/SQL / /

. DB2 Express Edition . . .

64 . PL/SQL JAVA Native Compilation Application .

6

DB2

DB2PointDB2 Express Edition, Workgroup Server Edition, Enterprise Server Edition . .

DB2 Express-C

DB2 Express (EXP)

Workgroup Server Edition (WSE) Linux, Windows AIX Linux Windows, AIX, HP-UX, Solaris 16GB 32/64bit 4CPU

Enterprise Server Edition (ESE) Linux, Windows AIX Linux Windows, AIX, HP-UX, Solaris

Linux, Windows

Linux, Windows

4GB 32/64 bit 32/64bit 2CPU

4GB 32/64bit 2CPU

32/64bit

CPU DB Size

DB2 ExpressC ,

.

.

. http://www.ibm.com/db2/express DB2 Express p // / / / / / http://www-306.ibm.com/software/data/db2/9/download.html

AS/400

S/390

DB2

DB2

.

DB2 iSeries DB2 zSeries

i5 OS zOS .

.

7

DB2

DB2 9.1PointDB2 , . , .

Express-C FTL Table Partitioning g Database Partitioning Connection Concentrator Governor Query Patroller Performance Expert MQT MDC Query Parallelism Compression: Row Level Compression : Backup Label Based Access Control Performance Expert

Express

WSE

ESE

Database Partitioning Feature Workload Management Feature for Express Workload Management Feature for Workgroup Performance Optimization Feature for Enterprise

Performance Expert

Performance Expert

Performance Optimization Feature for Express

Performance Optimization Feature for Workgroup

Storage Optimization Feature Advanced Access Control Feature Geodetic Data G d ti D t Management Feature

Geodetic Extender High Availability Disaster Recovery Online Reorganization Tivoli System Automation (TSA) PureXML Storage Homogeneous Replication Heterogeneous and Q Replication Homogeneous Federation Heterogeneous Federation WebSphere Replication Server PureXML Feature for Express PureXML Feature for Workgroup

High Availability Feature for Express

High Availability Feature for Workgroup

PureXML Feature for Enterprise

IBM Homogeneous Federation Feature for DB2 database WebSphere Federation Server

8

DB2

DB2 9.5PointDB2 , . , .

Express-C FTL g Q Homogenous SQL Replication Homogenous Q Replication High Availability Disaster Recovery Tivoli System Automation Online Reorg Advanced Copy Services MQT MDC Query Parallelism Connect Concentrator Table Partitioning Governor Homogenous Federation Database Partitioning Compression : Row Level Compression : Backup Label Based Access Control Geodetic Extender Query Patroller Workload Management Performance Expert PureXML Storage Net Search Extender Spatial Extender PureScale Data Sharing 1) Performance Expert

Express

WSE

ESE

Homogeneous Replication Feature for ESE

High A il bilit Hi h Availability Feature

Storage Optimization Feature

Advanced Access Control Feature Geodetic Data Management Feature

Performance Expert

Performance Expert

Performance Optimization Feature

DB2 PureScale Feature . DPF IBM Base

Data Partitioning Feature(DPF) DB2 Warehouse Edition Version 9.5 Warehouse Edition Feature for DB2 Version 9.5 .

9

DB2

DB2 9.7PointDB2 , . , .

Express-C FTL g Q Homogenous SQL Replication Homogenous Q Replication High Availability Disaster Recovery Tivoli System Automation Online Reorg Advanced Copy Services MQT MDC Query Parallelism Connect Concentrator Table Partitioning Governor Homogenous Federation Database Partitioning Compression : Row Level Compression : Backup Label Based Access Control Geodetic Extender Query Patroller Workload Management Performance Expert PureXML Storage Net Search Extender Spatial Extender PureScale Data Sharing 1) Performance Expert

Express

WSE

ESE

Homogeneous Replication Feature for ESE

High A il bilit Hi h Availability Feature

Storage Optimization Feature

Advanced Access Control Feature Geodetic Data Management Feature

Performance Expert

Performance Expert

Performance Optimization Feature

DB2 PureScale Feature . DPF IBM Base

Data Partitioning Feature(DPF) DB2 Warehouse Edition Version 9.5 Warehouse Edition Feature for DB2 Version 9.5 .

10

DB2

Point

DB2

DBMS

.

.

.

11g

IBM DB2 V9.X

Oracle RAC

HADR Enterprise Server Edition Workgroup Server Edition(DB2 9.5 ) .

.

DB Server

Oracle Partitioning

Data Partitioning DB2 Enterprise Server .

DB2 .

.

Data Guard

HADR . WebSphere Replication Server ( DBMS )

Server

.

.

IBM WebSphere Replication DBMS

Oracle RAC

Feature

Nothing

Shared Disk

DB2

Shared

.

Oracle Fine-Grained Auditing

DB2 Audit Utility

Audit

Business

.

Oracle Label Security

Label Based Access Control

Row Level

.

Enterprise Manager

DBMS

.

Oracle Diagnostic Pack

DB2 Engine

DB2

Oracle Diagnostic Pack

.

Oracle Tuning Pack (Diagnostic Pack

)

DB2 Engine

DB2

Oracle Tuning Pack

.

11

DB2

Point

DB2

.

.

JDBC, ODBC, API

11g

IBM DB2 V9 X V9.X DB2 IBM Data Server Runtime Client v9.7 IBM Data Server Client v9.X DB2 Client . Runtime DB2 Runtime Client RunTime Client

Client 11g

Client DB2 . Client Administrator, Custom DB2 Client . DB2 Client , ,

.

,

Transparent Gateway

DB2 Connect Enterprise Edition DB2 Connect Personal Edition

Mainframe

DB2

Client

.

11g Oracle Enterprise Manager Oracle SQL Plus Worksheet iSQL Oracle SQL Plus Oracle Net Config Assistant Oracle SQL Analyze ADDM (Automatic Database Diagnostic Monitor) Oracle SQL Developer )

IBM DB2 V9.X DB2 Control Center GUI SQL . SQL

DB2

. SQL . Access Plan . .

DB2

(CLP)

OS

.

DB2 Configuration Assistant DB2 Visual Explain db2exfmt, db2expln DB2 Data Server Developer Tool .

Stored procedure .

User Defined Function

12

DB2

DB2PointUnix/Linux/Windows DB2 . DB2 .

DB2 Client

Runtime Client

DB2 UDB

.

IBM Data Server Driver for JDBC and SQLJ

IBM Data Server Driver for JDBC and SQLJ JAVA SQL

Java

SQLJ

JDBC

JAVA .

(UDF)

.

IBM Data Server D t S Driver for ODBC and CLI

Data Server Driver for ODBC and CLI Data Server Client Data Server Runtime Client . tar . .

. CLI ODBC API

CLI API

IBM Data Server Driver Package

IBM Data Server Package Data Server Runtime Client CLI, .NET, OLE DB, PHP, Ruby, JDBC SQLJ

Data Server Client

ODBC,

.

ODBC, JDBC IBM Data Server Runtime Client DB2 V9 DB2 Runtime Client Runtime Client DB2 Run Time Client Lite DB2 V9.1 9.5 IBM Data Server Runtime Client

.

.

Run-Time Client IBM Data Server Client

, ,

GUI ,

. DB2 Administration Client V9.5 IBM Data Server Client

ESQL

DB2 V9

DB2 Application Development Client DB2 Client

DB2 V9 .

DB2 Connect

OS/390, AS/400

.

DB2 Connect Personal Edition DB2 Connect Enterprise Edition

Linux

Windows

.

Windows, AIX, HP UX Sola is Lin Windo s AIX HP-UX, Solaris, Linux, Linux/390 Lin /390 .

http://www-306.ibm.com/software/data/db2/9/download.html

DB2 Client

.

13

DB2

Point

IBM Optim

.

,

Optim IBM Optim Development Studio Optim Development Studio SQL XQuery Java SQL pureQuery IBM DB2 Data Server , , pureQuery

.

(Java

SQL)

Informix Dynamic Server

Optim pureQuery Runtime Java Optim pureQuery Runtime Optim PureQuery Runtime Java Java API pureQuery SQL . SQL

. .Java . . .

.NET NET

Linux, Linux UNIX

Windows .NET

Optim pureQuery Runtime ,

C#

VB.NET VB NET

.NET NET

.

Optim Database Administrator Optim Query Tuner

)

.

( :

,

,

,

DB2

Optim Query Tuner ,

.

InfoSphere Data Architect

Rational Data Architect , . , DDL

. . ( :SQL ) Optim Database Administrator ,

.

Perspective

,

. . ,

Data Studio

SQL SQL Visual Explain

Xquery SQL

SQL

,

14

DB2

DB2PointDB2 . , , z/OS .

DB2 Tools DB2 Web Query Tool , SQL , DB2 . SQL . . SQL . PDA, . , WAP DB2 ,

XML , DBA

. Windows, UNIX

Linux .

.

DB2 Recovery Expert

. ,

. . . (Point-in-Time)

DB2 High Performance Unload

, IBM DB2

. . . . .

IBM DBA DB2 Performance Expert Linux/Unix/Windows , (

, DB2 , )

SQL . . .

.

. DB2 Connect DB2 Encryption Expert .

DB2 B ffe pool Bufferpool

Management Expert

.

Change

15

DB2

3rd PartyPoint3rd Party DB2 .

DB2 Tools Orange for DB2 (WareValley) XpertMon for DB2 LUW (ITEG)

. DBA .

MaxGauge for DB2 (EXEM)

DB2

.

,

,

Toad for IBM DB2 (QUEST)

DB2 UDB

.

.

DB2

Quest Central for DB2 (QUEST)

SQL

,

,

,

z/OS

DB2

.

Spotlight on DB2 (QUEST)

Spotlight on DB2 UDB z/OS

.

,

DB2

Knowledge Xpert for DB2 (QUEST)

z/OS

,

DB2 UDB

.

DataFactory (QUEST)

,

.

Foglight Catridge for DB2/UDB (QUEST)

, DB2/UDB 24

, .

.

End User Management (QUEST)

.

16

DB2

Q/ADB2 Workgroup Server Edition k d RAC DB2 9.5 System FailOver l . . HADR DB2 . HADR Shipping .

Workgroup Server Edition HADR . Shared Disk dataguard .

DB2 . DB2 bulk load

? Compression Dictionary . bulk load DB2 insert, import, . .

DB2 Enterprise Server Edition DPF DPF DB2 9.5

DPF(Database Partitioning Feature) . ,

? .

IBM Base Warehouse Feature

.

DB2 DB2 . .

?

?

Oracle Enterprise Manager Diagnostic Pack

Oracle Label Security DB2 Label Based Access Control . DB2

DB2 . .

? Label Security .

IBM Corporation

IBM Corporation

Point

,

,

.

SGA Data Buffer Cache keep default (db_block_size) (db_cache_size) PGA sort_area_size t i hash_area_size bitmap_merge_area_size create_bitmap_area_size ASM PMON db_16k_cache_size db 16k cache size Large Pool ( ) SNPn SMON db_32k_cache_size db 32k cache size Java Pool ( ) ARCn DBWR CKPT LGWR Redo Log Buffers recycle db_2k_cache_size db_8k_cache_size Shared Pool Library Cache Dictionary Cache

MMON CKPT

MMAN Others

Parameter file Password file

Datafiles

Control files

Redo Log files

Archived log file

. System Global Area(SGA) 7 . OS Level nomount . . . .

2

DB2

DB2 9.7PointDB2 . , (DB2 9.5 ), DB2 DB2

DB2 Application App. Global Memory ( appl_memory) pp y) Application heap (applheapsz) Statistics heap (stat_heap_sz) Statement heap (stmtheap) Monitor Heap p (mon_heap_sz) db2ipccm (EDU) db2tcpcm (EDU)

DB2 Audit Buffer (audit_bug_sz) FCM Buffs(DPF) ( ) (fcm_num_buffers)

db2sysc (EDU) db2syslog ( (EDU) )

db2wdog (EDU) db2fmtlg (EDU)

db2resyn (EDU) db2thcln ( (EDU) ) others

db2agent

Agent Private Memory Agent stack ( agent_stack_sz) Sorting( sheapthres) Sort heap(sortheap) Java Heap(java_heap_sz) Client I/O block (rqrioblk) App. Shared Memory App.support layer heap (aslheapsz) Client I/O block (rqrioblk) db2loggr (EDU) db2loggw (EDU)

DB2 database_global_memory( database_memory) Database Heap (dbheap) Log Buffer (logbuffsz) (catalog_cache_sz) Utility Heap (util_heap_sz) Backup Buffer Package Cache (pckcachesz) Lock List ( locklist) Sorting (sheapthres_shr) Sort heap (sortheap)

db2pclnr (EDU)

db2dlock (EDU)

db2pfch (EDU)

others

DB2 . DB2 DB2 DB2 UDB ( DB2 DB2 DB2 , . DB2 Activate " . . Monitor Heap, Audit Buffer, FCM Buffer . ) EDU(Engine Dispatchable Unit) EDU

context .

.

.

3

DB2

Point

.

.

ASM

SNPn

ARCn

CKPT

MMOM

MMAN

PMON

SMON

DBWR

LGWR

CKPT

others others Others..

SQL (SQL LGWR DBWR * PMON SMON . Log Writer SGA ) SQL Parse, Execute, Fetch Redo Log File . .

. .

Redo Log Buffer Dirty Buffer Data File

Database Buffer

.

.

N/A

CKPT RECO ARCH *

. . Redo Log File Archiving 10 RAC Mode Flashback Storage 10 . . . Redo Log Archive Mode

.

SNPn * LCKn * RVWR ASM

(SNP0 ~ SNP10) (LCK0 ~ LCK10)

Table Snapshot Lock .

.

4

DB2

Point

DB2

.

Database Activate

. Level

Connection Client Program F I R E W A L L db2tcpcm (EDU) SAMPLE1 db2loggr (EDU) db2dlock (EDU) db2loggw (EDU) db2pfch (EDU) db2pclnr (EDU) others

db2agent (EDU) db2agntp db2agntp

db2ipccm (EDU)

Client Program

db2agent db2sysc (EDU) db2wog (EDU) SAMPLE2 db2agntp db2agntp db2loggr db2dlock db2loggw db2pclnr others

Agent pool

db2pfch

Level Db2sysc (System controller) Db2wdog (Watchdog) Db2resyn (Re-sync agent) db2fcms,db2fcmr (FCM daemon) Db2thcln (Thread Cleaner) Db2fmtlg Db2f tl (DB2 f format l ) t log) FCM(Fast Communication Manager) EDU(Engine Dispatchable Unit .) USEREXIT "OFF" OFF DBMS DB2 . Unix . Daemon Thread log . . ) Linux . DBMS

.

. (Unix LOGRETAIN . )

"ON" ON

db2ipccm, db2tcpcm ( Db2fmp (Fenced process) Db2loggr (Log Reader) gg ( g ) Db2loggw (Log Writer) Db2dlock (Deadlock detection) Db2pfchr (Pre-fetcher) db2pclnr(Page cleaner) db2stmm( Self turning memory) db2agent

dbtcpcm

.

db2ipccm User Define Function . . .

Stored Procedure

. . . . .

5

DB2

Point

DB2

.

.

Oracle PMON SMON ARCx Server DBWx CKPT LGWR . Server Process User Process User Process Server Process Softmax

DB2 db2wdog db2loggr . db2fmtlg db2cart

db2agent db2pclnr soft checkpoint Dirty page db2pclnr .

db2loggw db2dlock db2pfchr Db2ipccm (DB2 Communication Manager) Db2tcpcm (DB2 TCP Manager) Db2agent (DB2 Coordinating agent)

DB2 , DB2 DB2 DB2

IBM Ted Codd , , . .

.

. . : http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/index.jsp

6

DB2

Point

SGA

PGA

.

SGA PGA sort_area_size hash_area_size bitmap_merge_area_size create_bitmap_area_size db_16k_cache_size db_32k_cache_size Redo Log Buffers Large Pool ( ) Java Pool ( ) keep Data Buffer Cache recycle db_2k_cache_size db_8k_cache_size db 8k cache size Shared Pool Library Cache

default (db_block_size) (db_cache_size) (db cache size)

Dictionary Cache

Oracle SGA SGA_MAX_SIZE I/O DB_BLOCK_SIZE Block . . . SQL PL/SQL Meta Data . . Backup, Restore, LOAD . Java . PGA : : run-time . . PGA . Parsing g . . . . . . .

Buffer Cache

block

Shared Pool

Library Cache Dictionary Cache SHARED_POOL_SIZE Library Cache : Dictionary Cache : Block LOG_BUFFER SGA LARGE_POOL_SIZE SGA JAVA_POOL_SIZE PGA

Redo Log Buffer

Large Pool

Java Pool J P l

PGA

. Private SQL Session

7

DB2

Point

DB2

.

,

,

,

,

global

, Agent Private .

,

Monitor Heap (mon_heap_sz)

Audit Buffer (audit_bug_sz)

FCM Buffs(fcm_num_buffers)

.

Sample1 ( database_memory) BufferPool ff l ( buffpage) Database Heap (dbheap) Log Buffer (logbuffsz) Package Cache (pckcachesz) Catalog Cache (catalog_cache_sz) Utility Heap (util_heap_sz) Sorting g (sheapthres_shr) Sort heap (sortheap) Lock List ( locklist)

Sample2 ( database_memory)

Sample1

.

Global ( appl_memory) Application heap (applheapsz) Statistics heap (stat_heap_sz) Statement heap (stmtheap)

Agent Private Agent stack (agent_stack_sz) Java Heap (java_heap_sz) Sorting (sheapthres) Sort heap (sortheap) App.support layer heap (aslheapsz) Client I/O block (rqrioblk)

Client I/O Block(rqrioblk)

instance_memory

. . Default Automatic .

. Automatic . DB2

/

,

. , SQL Q

. . . . . . .

Global

Database Agent stmtheap, stat_heap_sz, applheapsz . ahhpleahsz : DB stat_heap_sz : RUNSTATS stmtheap : SQL Xquery Database Agent

Agent Private

8

DB2

Point

DB2

.

.

Oracle

DB2 Database Manager Database Shared Memory

SGA

.

I/O . : Default Buffer Cache BufferPool DB2 : init.ora

Block

Keep, Recycle . . . .

.

CREATE BUFFERPOOL ~ .

.

Redo Log Buffer

Log Buffer

.

Block

Library Cache

Package Cache Meta Data Catalog

. Data Dictionary

Dictionary Cache

Catalog Cache

, DB2

.

Application Heap PGA Agent Private Memory DB2 :

. : . Application Heap .

Large Pool

Utilities Heap Lock List

Backup, Restore, LOAD Lock .

.

9

DB2

Point

Optimal Flexible Architecture(OFA)

.

/u01/app/oracle /product/11.1.0/db_1 /bin /dbs /lib /network /admin

ORACLE_BASE ORACLE_HOME

Spfile.ora

Default Init.ora

Shared Library Path

Tnsnames.ora

listener.ora

/admin / /adump /pfile /scripts / i t Audit File

/diag /oradata / /controlfile /datafile /onlinelog / li l control.ctl data.dbf redo.log d l

** ASM

.(

11.1.0

.)

10

DB2

Point

root Default

.

DB2

DB2

, OS

.

Windows AIX DB2 V9.7

.

< Windows > Program FilesIBMsqllib bin < Windows XP DB2 Windows 2003 > /sqllib /bin db2dump < Windows Vista > DB2 db2diag.log DB2 Default /opt/IBM/db2/V9.7

< Unix > DB2 Default

/$DB2_HOME

C:Documents and SettingsAll UsersApplication DataIBMDB2DB2COPY1DB2

DB2

/sqldbdir /db2dump DB2 db2diag.log

C:ProgramDataIBMDB2DB2COPY1DB2 db2dump DB2 db2diag.log < > . .

NODE0000 < DB Name> T00000000 T00000001 T00000002 SYSCATSPACE TEMPSPACE1 USERSPACE1

. .

sql00001

Database ID (SAMPLE Default LOG DMS SMS

)

SQLLOGDIR dms_ts.dat sms_ts

. SQLTAG.NAM : SQL*.LF : LONG VARCHAR, LONG VARGRAPHIC SQL*.LB : BLOB, CLOB, DBCLOB SQL*.LBA : SQL*.LB Free SQL*.INX : .

. . . .

11

DB2

Q/ASGA DB2 . page . Buffer Cache ? . DB2 . page Buffer Cache

undo . DB2 DB2

Undo Segment( Undo Data . .

Rollback Segment) ? Data

Data Multi Version

Multi Version ?

Undo Data redo log buffer . Select Lock . DB2

DB2 V9.7 DB2 Undo Data(Before Image) Isolation Level . . DB2

Log Buffer

DB2

DB2 ? 10GB 650MB ~ 1GB . . . DB2 . DB2 link . . . DB2

1GB DB2

.

IBM Corporation

DB2

IBM Corporation

Point

DB2

.

.

DB2 v9.5

DB2

Resource esou ce 800MB Linux / Unix DB2 512MB RAM . . DB2 1GB RAM . . DB2 GUI . DB2 600MB ~

/tmp .

2GB 256MB RAM

Platform

AIX

5.3 AIX 5.3 TL(Technology Level) 9, C++ xlC.rte 9.0.0.8 9.0.0.8( ) . C++ Runtime Environment Components . AIX 6.12 AIX 6.1 TL2 C++ AIX 5.3

AIX

2 (SP2) xlC.aix50.rte 2008 6 IBM for AIX

64 AIX 64 CHRP(Common Hardware Reference Platform) AIX (CHRP lscfg

Model Architecture: chrp)

.

HP-UX

HP-UX 11iv2 (11.23.0505) 2005 5 Base Quality (QPKBASE) 2005 5 Applications Quality(QPAPPS) HP-UX 11iv3 (11.31) (11 31) Red Hat Enterprise Linux(RHEL) 5 Update 2 SUSE Linux Enterprise Server(SLES) 10 Service Pack 2 SUSE Linux Enterprise Server(SLES) 11 Upuntu 8.0.4.1

Itanium

HP Integrity Series

Linux

x86(Intel Pentium, Intel Xeon, AMD) 32-bit Intel AMD x64(64-bit AMD64 Intel EM64T ) POWER(IBM eServer OpenPower, System i) Linux pSeries eServer System z or System z9

Solaris 9 Solaris 111711-12 and 111712-12 122300-11 Fujitsu PRIMEPOWER 9 112233-01 Solaris 10 5 Raw 125101-07 Raw 64 Windows XP Professional (32 x64) Windows XP Professional 2 Windows Vista Business/ Enterprise/ Ultimate (32 x64) Windows 2003 Standard/Enterprise/DataCenter Edition (32 x64) Windows 2008 Standard/Enterprise/DataCenter Edition (32 x64)

64 UltraSPARC

Window

Windows Intel

AMD

(32

64

)

http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp .

2

DB2

Point

DB2

.

.

Windows Wi d DB2

Linux Li (X

Unix U i ) 10 ~ 20 5 ~ 10

db2_install

5 ~ 10

DB2 DB2 DB2

Linux, Unix

Windows . root

GUI .

. DB2

DB2

) Linux / Unix

Resource

DB2

.

.

root

. DB2 DB2 DB2 Unix : . DB2 DB2 . . . . DB2 DB2

.

Linux DB2

DB2 -L db2_install DB2 , , . .

DB2 . . .

.

DB2

DB2 Express C

.

. http://www.ibm.com/db2/express

DB2 Express

3

DB2

DB2PointDB2 .

DB2

R t Root

.(Unix

.

Linux

DB2 V9 7 V9.7 root Root

t root .) Root . DB2 V9.7

.

DB2

? ? .

. . DB2 . ($HOME/sqllib)

DB2

?

.

.

Root DB2 Root Root DB2 root : DB2 root . 9.7 Linux root Root . DB2 root DB2 , FixPack . , . root root DB2 .

Unix DB2

DB2 E b d d Embeded (DB2 EAS) DB2 Query Patroller DB2 Net Search Extender DB2 : root DB2 Administration Server(DAS) db2governor g Work Load Manager(WLM) root DB2 Health Monitor . db2ls : root ulimit root db2rfe : root (HA) /etc/services : root root : root

. ( ) dascrt, daslist, dasmigr . root DB2 SQLCODE . .( db2ls

dasupdt)

. ) .

. root root .( ) db2icrt, db2iupdt, db2idrop, db2imigr) . db2rfe .

.

4

DB2

Point

DB2 Enterprise Server

.

1. DB2 Enterprise Server Edition CD

db2setup

.

.

2. DB2 Enterprise Server Edition . DB2 Client Data Server Client 9.7

9.7

.

IBM

5

DB2

Point

DB2

.

5. .

.

.

.

7. DB2 . Default C:Program FilesIBMSQLLIB

.

Window

8. DB2 . 6. DB2 Server " "

.

DB2

.

6

DB2

Point

DB2

.

9. DB2 60000

. . Default .

Listen 50000

11.

.

DB2 .

DB2

DB2

12.

SMTP

.

10.

. OS

DB2 OS .

OS

7

DB2

Point

DB2

.

13. DB2

DB2

,

,

.

15. DB2 " " .

.

.

14. . " "

.

DB2

16. Visual Studio 2005 Visual Studio 2005 " " .

DB2

DB2 .

.

8

DB2

Point

DB2

.

17. DB2 HR Schema SAMPLE .

DB2

Sample "

. SAMPLE

18. .

"SQL

"XML SAMPLE

SQL

"

. .

. "

XML

.

9

DB2

Point

DB2

AIX

db2_install

.

1. DB2

. . .

. OS

DB2

db2prereqcheck

4.

/tmp/db2_install.log. . Task #43 end Task #44 start Description : Initializing instance list Estimated time 5 second Task #44 end

.

XL C++ Runtime

Upgrade

/sw_image/db2v97/DB2_ESE_V97>./db2prereqcheck 2. db2_install .

h

/sw_image/db2v97/DB2_ESE_V97>./db2_install h DBI1045I Usage: db2_install [ -b ] [-p ] [ -c ] [-l] [-f NOTSAMP] [ -t ] [-n] [-L ] [-h | -?] Explannation: -b This option is mandatory for root install when n is specified but optional for non-root install.

Task #45 start Description : Updating global profile registry Estimated time 3 second./db2_install Default directory for installation of products /opt/IBM/db2/V9.7 ************************************************* Do you want to choose a different directory to install[yes/no]? no Specify one of the following keywords to install DB2 products products. ESE CLIENT RTCL Enter help to redisply product names. Enter quit to exit. ************************************************** ESE

Installing DB2 file sets:...........Success Setting DB2 library path:........Success installing or updating SA MP Base Component:..........Success Installing national language support for SA MP Base Component:..........Success Installing or updating DB2 HA scripts for SA MP Base Component:...........Success Updating global registry: registry:..........Success Success The installation of IBM Tivoli Monitoring for Database has completed.

10

DB2

Point

db2_install

DB2

.

.

1. root

.

Owner DB2 DB2 .

.

:/> mkgroup db2igrp :/> mkuser pgrp=db2igrp inst97 :/> mkgroup db2fgrp :/> mkuser pgrp=db2fgrp fenc97

:/>cd /opt/IBM/db2/V9.7/instance /opt/IBM/db2/V9.7/instance>./db2icrt u fenc97 inst97 DBI1070I Program db2icrt completed successfully.

3.

Owner SAMPLE Schema

owner .

su "db2sampl" . sample HR

:/> su inst97 $db2sampl Starting the DB2 instance ... Creating database SAMPLE... Connecting to database SAMPLE... Creating tables and data in the schema INST97... Stopping the DB2 instance... db2sampl processing complete.

11

DB2

Point

root

DB2 . OS

DB2

DB2 V9.7

.

.

Windows

AIX

< Windows >

< Unix >

$DB2_HOME bin bnd cfg DB2 FUNCTION program filesIBMsqllib

DB2 .

/$DB2_HOME bin bnd cfg db2dump FUNCTION

DB2 /opt/IBM/db2/V9.7 .

. . . SYSCATSPACE TEMPSPACE1 USERSPACE1 .

NODE0000 < DB Name> T00000000 T00000001 T00000002

sql00001

Database ID (SAMPLE Default LOG DMS SMS

)

SQLLOGDIR dms_ts.dat sms_ts

. SQLTAG.NAM : SQL*.LF : LONG VARCHAR, LONG VARGRAPHIC SQL .LB : BLOB, CLOB, SQL* LB BLOB CLOB DBCLOB SQL*.LBA : SQL*.LB Free SQL*.INX : .

. . . .

12

DB2

Point

DB2

.

1. DB2 Administration Server(DAS) DB2 DB2 DAS "db2cmd" .

4. . DAS . DAS "db2admin start" . =>

=> . .

=>

=> IBM DB2 => DB2COPY1( DB2

) =>

2. DB2 CLP

.

"db2admin"

DAS

C:> db2admin DB2DAS00

3. DAS

"

DAS

"

.

.

C:> db2admin start SQL4409W DB2 Administration Server .

13

DB2

Point

DB2

.

5.

.

.

7. Feature

. 25 .

DB2 License .

6.

(db2eseX.lic

)

.

8.

Feature

Feature

.

14

DB2

Point

DB2

AIX

db2_install

.

1. root Default db2licm .

adm -l

DB2 /opt/IBM/db2/V9.7 .

. license

. DB2 V9.7

/opt/IBM/db2/V9.7/admin>./db2licm -l : : : ID: : " "db2ese" "9.7" "DB2 Enterprise Server Edition " " "

2.

a db2ese-c.lic

.

.

db2licm

/opt/IBM/db2/V9.7/admin>./db2licm a /db2lic/db2ese_c.lic LIC1402I License added successfully. LIC1426I This product is now licensed for use as outlined in your License Agreement. USE OF THE PRODUCT CONSTITUTES ACCEPTANCE OF THE TERMS OF THE IBM LICENSE AGREEMENT, LOCATED IN THE FOLLOWING DIRECTORY: /opt/IBM/db2/V9.7/license/en_US.iso88591

3. Feature .

1

db2licm

db2licm

.

/opt/IBM/db2/V9.7/admin>./db2licm l Prodct name : License type: Expiry date: Product identifier: Version Information: DB2 Enterprise Server Edition DB2 Edition CPU Option Permanent db2ese 9.7

15

DB2

Point

DB2

.

1. Client setup.exe

.

DB2 . IBM Data Server Client

CD

3.

.

2.

"

"

.

4.

Component

. .

100~200M " "

"

. "

DB2 Client

http://www-306.ibm.com/software/data/db2/9/download.html

.

16

DB2

Point

DB2

.

5. IBM Data Server Client

7. Client .

.

6.

8. .

DB2

DB2

.

DB2

.

IBM Data Server Client DB2 . IBM Data Server Client ( V9.7 IBM Data Server Client IBM Data Server Runtime Client IBM Data Server Driver for ODBC, CLI

SQL . 1 .)

.

.NET

17

DB2

Point

DB2

.

10.

"

"

.

.

18

DB2

Point

DB2

.

1.

DB2 DB2

db2swtch . .

4.

(Drop) SAMPLE .

2. 2

. SAMPLE . " " TOOLSDB

. TOOLSDB

DB2

3.

. .

.

5. DB2 .

.

DB2

19

DB2

Point

DB2

.

6. /

DB2

.

db2unins : db2unins -p : p db2unins -f : . db2unins -d : .

DB2 DB2 DB2 DB2

.

C:DownloadDirectordb2_97_win> db2unins f

7.

.

20

DB2

Point

DB2

AIX

.

1. inst95

. list applications . "list applications" list applications . . .

2. list db database " $ db2 list db directory System Database Directory .

Drop Database .

.

force applications all

Number of entries in the directory = 1 Database 1 entry : Database alias Database Name Local database directory Database release level Comment Directory entry type Alternate server hostname Alternate server port number $db2 drop db sample = = Indirect = = = SAMPLE = SAMPLE = /home/inst97 = c.00

list applications . /opt/IBM/db2/V9.7/admin>su i t97 / t/IBM/db2/V9 7/ d i inst97 $ db2start

06/11/2009 09:30:41 0 0 SQL1063N DB2START processing was successful. SQL1063N DB2START processing was successful. $ db2 connect to sample Database Connection Information Database server Local database alias $ db2 list applications Auth Id Application Name Appl. Handle Application ID pp pp pp DB Name INST97 db2bp SAMPLE 7 # of Agents *Local.inst97.000611003047 1 -------------------------------------------------------------------------= DB2/AIX64 9.7.0 = SAMPLE SQL authorization ID = INST97

Catalog database partition number = 0

3. db2stop . root db2idrop $ db2stop force

DB2DIR/instance .

06/11/2009 09:37:38 0 0 DB2STOP processing was successful. SQL1064N DB2STOP processing was successful. /opt/IBM/db2/V9.7/instance>./db2idrop inst97 4. 4 db2ls DB2DIR/install DB2 . "db2_deinstall a" . DB2DIR DB2 .

$ db2 force applications all DB20000I The FORCE APPLICATION command completely successfully. DB21024I This command is asynchronous and may not be effective immediately.

DB2

/opt/IBM/db2/V9.7/instance>db2ls Install Path Level Fix Pack Special Install Number Install Date Installer UID -------------------------------------------------------------------------/opt/IBM/db2/V9.7 9.7.0.0 KORST 0 0 Wed Jun 11 08:00:26 2009

/opt/IBM/db2/V9.7/instance>cd ../install /opt/IBM/db2/V9.7/instance>./db2_deinstall -a DBI1016I Program db2_deinstall is performing uninstallation. Please wait.

21

DB2

DB2AIX

Q/ADB2 Enterprise Server Edition DB2 Server SA MP Base Component ? Linux DB2 . db2/aix/tsamp installSAM . Tivoli HA(High Availability) SA MP Base . ?

SA MP Base Component AIX Component AIX Linux IBM Data Server AIX Linux IBM Data Server Cluster DB2 Enterprise Server Edition . DB2 CD .

SA MP Base Component

, . DB2 . DB2 DBA . ?

, OS .

. DB2 settingsAdministratorMy DucumentsDB2LOGDB2-ESE-< db2_install.log. . .

? >.log Unix c:Doments /tmp

DB2 . . Unix

.

? .

DB2 V9.1 ? . DB2 V9.1 DB2 V9.7 Fixpak

. DB2 V9.1 . .

DB2 V9.7 Fixpak

DB2 Client V8.2

.

V9.7

Upgrade .NET

Client .

?

DB2 Client V8.2 V9 DB2 Server V 9.7 Runtime Client IBM Data Server Driver for ODBC, CLI .

IBM Data Server Client, IBM Data Server V9.7 DB2 V9.X V8.2 . .

http://www.ibm.com/software/data/udb/sysreq.html

IBM Corporation

IBM TSS Techline

Command Line DB2

IBM Corporation

Point

DB2

.

DB2

.

DB2

Oracle Manager

DB2 Database Shared Memory

init.ora ( ORACLE_SID ORACLE SID alert log

SPFILE )

DBM Configuration File Database Configuration File DB2INSTANCE Administration Notification Log Diagnostic Log (db2diag.log) Buffer Pool Database Manager Database Shared Memory Package Cache Utility Heap Catalog Cache Application Shared Memory Agent Private Memory Application Global Memory Session DB Connection SQL Backup, Restore, LOAD Meta Data Dictionary, DB2 y, Catalog g ( ) Data DB DBMS I/O DBMS Block

bdump directory Data Buffer Cache System Global Area (SGA) Library Cache Large Pool Data Dictionary Cache program global area User Global Area (UGA) session

.

DB2

.

2

DB2

Point

DB2

.

DB2

.

DB2

Oracle

DB2

SYSTEM Datafile Segment Extent Data block partitioned tables Data dictionary Dual Table global temporary table ROLE Dynamic Performance Views

SYSCATSPACE Container Storage Object Extent Data Page Partitioned Tables System Catalog Dual Table Global Temporary Table ROLE Snapshot Monitor SQL Administrative Views nickname Alias Nonpartitioned Index Partitioned Index Materialized Query Table M i li d Q T bl (MQT) N/A Package

Meta Data Dictionary, DB2 Catalog

Data

Block ,

Database Dummy Table y

DBMS SYSIBMADM

. (

View

DB2

SYSIBMADM.SNAPBP )

Database Link synonym global index local index materialized View Package N/A

Federated Database

1 VIEW PL/SQL Block Static Embedded SQL

1

.

DB2

.

3

DB2

Point

DB2

.

DB2

.

DB2

Oa Oracle Redo Log Files Active Log Inactive Log Archive Log Archive Log Mode Noarchive Log Mode

DB2 Transaction Log Files Active Log Online-archive Log Offline-archive Log Log Archiving Circular Logging Archive

Oracle Oracle Call Interface (OCI) PL/SQL

DB2 Call Level Interface (CLI) SQL/PL C C++ SQL Q DB2 V9.7 PL/SQL

.

DB2

.

4

DB2

SQLPointDB2 SQL SQL SQL , . SQL . SQL .

SQL SQL . ( DB2 , / , / , . ) . ANSI SQL . / / . .

PL/SQL

DB2 SQLPL PL/SQL DB2 SQLPL DB . SQL PL(SQL Procedural Language) SQL SQL

PL/SQL(Procedural Language/SQL)

.

SQL SQL

3

SQL

SQL/PSM(SQL Persistent Stored Modules)

) Oracle PL/SQL DB2 SQLPL . DB2 SQLPL SQL/PSM DB2 SQLPL Oracle PL/SQL DB2 V9.7 PL/SQL

Oracle PL/SQL Oracle PL/SQL 3 Syntax . PL/SQL

DB2 SQLPL SQL .

DB2 Command Line Interface SQL*Plus iSQL*Plus Enterprise Manager DB2 DB2 DB2 CLPPlus (DB2 9.7

New Feature)

Thrid party

Toad WareValley Orage

Toad for DB2 WareValley Orage

5

DB2

Command LinePointProcessor . SQL Command line . . Sql*Plus DB2 Command Line

DB2 qpu sqlplus c p(co clp(command line processor) a d e p ocesso ) GU GUI . db2 . . OS DB2 OS

DB2 DB2 /home/inst95> sqlplus / as sysdba SQL> select * from emp;

DB2

. : /home/inst95> db2 db2=> select * from emp db2=> : /home/inst95/>db2 select * from emp /home/inst95/>ls la

db2=> quit DB2 SQL>quit db2=> terminate . /home/inst95> db2 tvf ) -t: (;) -v: v: . -f < >: . db2=> help [ ] db2=> EDIT db2=>! db2=> HISTORY db2=> runcmd ? db2=> ? . .

SQL> @test.sql

.

CLP

SQL> help set SQL> EDIT SQL> !

> .

db2=> ? SQL SQLCODE .

6

DB2

DB2 V9.7PointDB2 V9.7 CLPPlus sql*plus .

command Linesql*plus clpplus . SQLPlus

SQLPlus

DB2 CLPPlus

SQLPlus c:> sqlplus [ @connect_identifier ]

DB2 CLPPlus c:> Clpplus [/@ :/ ] SQL> CONNECT [@:/< DBName> ] SQL> QUIT SQL> @test.sql SQL> / SQL> R[UN] SQL> EXEC[UTE] SQL> GET plsql.sql SQL> EDIT plsql.sql Q p q q SQL> SAVE test.sql SQL> SHOW [option] SQL> SPOOL [ output file | OFF ] SQL> DESCRIBE [schema.object] SQL>COLUMN [column name] [FORMAT FOR spec | HEA[DING] text] ) COLUMN JOB FORMAT A5 ) COLUMN SAL FORMAT $99,999.00 SQL>COMPUTE [SUM | MAX | MIN | AVG | COUNT | NUM | STD | VAR] [LABEL text OF column1 on column2 ] SQL> BREAK ON column-name [ SKIP | PAGE | ] SQL>[ HELP|?] [ INDEX | topic ] SQLPlus topic column2 format . . , SQL SQLPlus CLPPlus OS PL/SQL . SQL Buffer . . . . . DB2

DB

DB Name

.

SQL> CONNECT [ @connect_identifier ] @connect identifier SQL> QUIT SQL> @test.sql SQL> / SQL> R[UN] SQL> EXEC[UTE] SQL> GET plsql.sql SQL> EDIT plsql.sql Q p q q SQL> SAVE test.sql SQL> SHOW [option] SQL> SPOOL [ output file | OFF ] SQL> DESCRIBE [schema.object] SQL>COLUMN [column name] [FORMAT FOR spec | HEA[DING] text] ) COLUMN JOB FORMAT A5 ) COLUMN SAL FORMAT $99,999.00 SQL>COMPUTE [SUM | MAX | MIN | AVG | COUNT | NUM | STD | VAR] [LABEL text OF column1 on column2 ] SQL> BREAK ON column-name [ SKIP | PAGE | ] SQL>[ HELP|?] [ INDEX | topic ]

SQLPlus

.

CLPPlus

DB

SQLPlus .

CLPPlus SQLPlus SQL PL/SQL SQL PL/SQL SQL SQL .

.

.

. . .

column1 BREAK Break

CLPPlus

.

7

DB2

DB2 V9.7PointDB2 V9.7 CLPPlus sql*plus .

command Linesql*plus clpplus . SQLPlus

SQLPlus

DB2 CLPPlus

SQLPlus SET ARRAYSIZE [ 1 ~ 5000 : default 15] SET AUTO[COMMIT] [ ON | OFF | IMMEIDATE | n ] SET COLSEP [ Column separator ] SET ECHO [ ON | OFF ] SET HEA[DING] [ ON | OFF ] SET LIN[ESIZE] [ 1~ : Default : 80 ] SET NEWP[AGE] SET NULL text SET PAGES[IZE] [1~ : default: 14] SET PAU[SE] [ON | OFF] SET SERVEROUTPUT [ON | OFF] SET TIMI[NG] [ON | OFF ]

DB2 CLPPlus SET ARRAYSIZE [ 1 ~ 10000 : default 10] SET AUTO[COMMIT] [ ON | OFF | IMMEIDATE | n ] SET COLSEP [ Column separator ] C l t ) SQL> SET COLSEP | SET ECHO [ ON | OFF ] SET HEA[DING] [ ON | OFF ] SET LIN[ESIZE] [1~32767 : Default : 80] SET NEWP[AGE] SET NULL text ) SQL> SET NULL SET PAGES[IZE] [2~50000 : default: 14] SET PAU[SE] [ON | OFF] SET SERVEROUTPUT [ON | OFF] SET TIMI[NG] [ON | OFF ] . text NULL . . . . . . SQLPlus CLPPlus fetch row COMMIT

.

. .

Enter DBMS_OUTPUT SQL

. .

.

SQL> SQL> SQL> SQL> SQL> SQL>

SET AUTOCOMMIT ON SET NULL SET PAU ON insert into t1 values (1,'a'); (1 a ); insert into t1 values (1,null); select * from t1; ENTER .

C1|C2 -----------|-------------------1 |a 1 |-3 .

SQL> set serveroutput on SQL> get test 1 create or replace procedure count_emp() 2 begin 3 declare i integer default 0; 4 set i=(select count(*) from kr010389.employee); 5 call dbms_output.put_line('count=' || varchar(i)); 6* end; SQL> exec count_emp(); count=42 DB250000I: .

8

DB2

DB2 CLPPointDB2 SQL .

1. " DB2

=>

=> .

=> IBM DB2 => DB2COPY1( ) => . "db2=> . db2cmd . db2 connect to sample .

3. db2

OS . .

!

db2 => !dir | more (c) Copyright IBM Corporation 1993,2007 DB2 Client 9.7.0 (CLP) . : db2 => connect to sample tt l db2 => bind sample.bnd ? ? SQL C : 6806-ABBD C:Program FilesIBMSQLLIBBIN 2009-09-18 2009-09-18 2009-05-30 2009-05-30 2009-05-30 08:30 08:30 08:38 08:38 08:38 . .. 791,840 asnacmd.exe 1,168,672 asnadmt.exe 189,728 asnadmtora.exe .

. .

. : ? CATALOG DATABASE: CATALOG DATABASE ? CATALOG: db2 CATALOG 'db2' . LIST COMMAND OPTIONS . db2=> db2 => connect to sample tt l QUIT .

4. DB2 DB2

.

? .

SQL catalog

.

db2 => ? catalog tcpip CATALOG [ADMIN] {TCPIP | TCPIP4 | TCPIP6} NODE nodename REMOTE hostname [SERVER service name] service-name] [SECURITY {SOCKS | SSL}] [REMOTE_INSTANCE instancename] [SYSTEM system-name] [OSTYPE os-type] [WITH "comment string"] : SERVER service-name CATALOG {TCPIP | TCPIP4 | TCPIP6} . NODE CATALOG ADMIN {TCPIP | TCPIP4 | TCPIP6} NODE . SECURITY SOCKS CATALOG [ADMIN] TCPIP6 NODE .

SQL

ID

= DB2/NT 9.7.0 = KR010389 = SAMPLE

2. SAMPLE Database db2 => list tables

list tables

.

/ --------------- --------------- ----- -------------------------ACT KR010389 ADEFUSR KR010389 CATALOG KR010389 CL_SCHED KR010389 T 2009-09-28-15.08.33.312018 S 2009-09-28-15.08.37.078003 T 2009-09-28-15.08.43.609003 T 2009-09-28-15.08.31.093002

9

DB2

DB2 CLPPointDB2 SQL .

5. a.sql -tvf

.

DB2 T1, T2, T3 SAMPLE

SQL .

7. EDIT

SQL .

C:> notepad a.sql drop table t1; drop table t2; drop table t3; create table t1(c1 int); create table t2(c1 int); create table t3(c1 int); C:> db2 tvf a.sql drop table t1 DB20000I SQL drop table t2 DB20000I SQL drop table t3 DB20000I SQL create table t1(c1 int) DB20000I SQL create table t2(c1 int) DB20000I SQL create table t3(c1 int) DB20000I SQL

db2 => history 1 2 3 create table t1(c1 int) ? SQL0601N history

db2 => EDIT 1 ( ) db2 => create table t4(c1 int) ? (y/n) y DB20000I SQL db2 => . . . . db2 => history . . 1 2 3 4 . ? . create table t4(c1 int) ? SQL0601N history list tables 8. history runcmd < . > .

6.

SQL Statement

db2 => runcmd 4 / --------------- --------------- ----- -------------------------ACT KR010389 ADEFUSR KR010389 CATALOG KR010389 CL_SCHED KR010389 T 2009-09-28-15.08.33.312018 S 2009-09-28-15.08.37.078003 T 2009-09-28-15.08.43.609003 T 2009-09-28-15.08.31.093002

db2 =>create table t1 ( c1 int) DB21034E . SQL . "TABLE" . SQLSTATE=42710

SQL SQL0601N "KR010389.T1" ( ) db2 => ? SQL0601N SQL0601N "" ( ) . : "" , CREATE "" ( )

""

ALTER

.

10

DB2

DB2 V9.7PointSQLPlus .

CLPPlusDB2 CLPPlus SQLPlus DB2 CLPPlus

1. CLPPlus C:/> clpplus

SAMPLE

.

3. Column .

SALARY

format

CLPPlus : Version 1.0 Copyright (c) 2009, IBM CORPORATION. All rights reserved. SQL> connect db2admin/db2admin@localhost:60000/sample Data base Connection Information Hostname = localhost Database Server = DB2/NT SQL09070 Local database alias = SAMPLE Port = 60000

SQL> column salary format $99,999.00 SQL> select empno,salary from kr010389.emp; EMPNO | SALARY -------------|-----------------000010| ########## 000020| $94,250.00 000030| $98,250.00 000050| $80,175.00 000060| $72,250.00 000070| $96,170.00 000090| $89,750.00 000100| $86,150.00 000110| $66,500.00 000120| $49,250.00 $49 250 00 000130| $73,800.00

2. SQL> HOST dir

.

CLPPlus

SQL> SET SERVEROUTPUT ON SQL> GET test.sql 1 create or replace procedure count_emp() 2 begin 3 declare i integer default 0; 4 set i=(select count(*) from kr010389.employee); 5 call dbms_output.put_line('count=' || varchar(i)); 6* end; 3. Column . SALARY Format

SQL> BREAK ON WORKDEPT SKIP 2; SQL> COMPUTE AVG LABEL Average OF SALARY A e age 2 ON WORKDEPT; SQL> COMPUTE MAX LABEL Maximum OF SALARY 2 ON WORKDEPT; SQL> SELECT WORKDEPT, EMPNO, SALARY 2 FROM EMPLOYEE ORDER BY WORKDEPT ; WORKDEPT|EMPNO | SALARY ---------------|-----------|---------------------| | A00 |000010 | ########## A00 |000110 | $66,500.00 A00 |000120 | $49,250.00 A00 |200010 | $46,500.00 A00 |200120 | $39,250.00 ******** --------------------Average g 70850.00 ******** --------------------maximum 152750.00 B01 |000020 | $94,250.00 ******** --------------------Average 94250.00 ******** --------------------maximum i 94250.00 94250 00

3. CLPPlus RUN Procedure SQL> / DB250000I: SQL> call count_emp(); count=42 DB250000I:

/

.

procedure

.

.

SQL> execute count_emp(); count=42 DB250000I: .

11

DB2

DB2PointDB2 GUI SQL .

1.

=>

=>

=> IBM DB2 => DB2COPY1( . .

) =>

3.

.

4.

=>

.

2. "list tables" .

"describe table employee

.

12

DB2

Q/ADummy A10" ? DB2 V9.7 DB2 CLPPlus . DB2 CLPPlus . SQLPlus COLUMN FORMAT A10 DB2 CLPPlus column 10 . "COLUMN FORMAT

IBM Corporation

IBM Corporation

Point

DB2

.

DB2

.

DB2

Oracle

DB2 (DatabaseManager) Shared Memory

Data Buffers SGA Library Cache Large Pool Data Dictionary Cache sqlplus PL/SQL Package N/A

Buffer Pool Database Manager Database Shared Memory Package Cache Utility Heap Catalog Cache command line processor (clp) SQL/PL N/A Package DBM Configuration File Database Configuration File

I/O

Block

Backup, Restore, LOAD Dictionary Meta Data , DB2 Catalog client SQL . Data

Client Procedure PL/SQL Block static embedded SQL

DBMS ,

Database Link Redo Log Files Alert Log Archive Redo Log Autoextend Materialized View

Federated System Transaction Log Files Administration Notification Log DB2Diag Log Archive Log Autoresize Materialized Query Table (MQT)

Datafiles Segments Extents Data blocks Data dictionary

Containers Objects Extents Pages System catalog

Database Block

2

DB2

Point

DBA

. . .

. DB2

DB2 Oracle SID = ORA11g DB2 Instance = db2inst1

catalog Data Password DB Name : ORA11g Redo Log DB Config DB Name : SAMPLE1

Control

catalog Log DB Config

DB Name : SAMPLE2

SGA

DBM Config

SET ORACLE_SID=ORA11g SQL> Connect / as sysdba SQL> startup

SET DB2INSTANCE=db2inst1 db2start

SPFILE . .

Oracle SID

.

DB2 DB2 . Registry .

Database Manager

.

. PFILE

. DBM Configuration File

DB Config

.

DB2 . . startup . DB2

DBA

. DB2

.

DB2

SGA Activate .

Mount

Open

3

DB2

Point

DB2

.

.

DB2 ORACLE_SID ORACLE SID . db2icrt * db2idrop ORACLE_SID . * ps ef | grep pmon /etc/oratab / t / t b . SET ORACLE_SID = sqlplus startup . OS . db2ilist * . SET DB2INSTANCE = DB2 Path . OS . . . . . . .

SQL> startup [ NOMOUNT | MOUNT | OPEN ] Q p

/home/inst32/db2start [ admin mode ] DB2 db2stop Path OS

sqlplus

shutdown

.

SQL> shutdown [ NORMAL | TRANSACTIONAL | IMMEDIATE | ABORT ] SQL SQL> select banner from v$version SQL SQL> opatch lsinventory -all all . .

.

/home/inst32/db2stop [ force ]

db2level

DB2

.

/home/db2inst1> db2level db2ls DB2

.

/home/db2inst1> db2ls

startup nomount startup shutdown immediate DB2 force force

DB2 ( ,db2start db2start Activate rollback . db2stop application .

) shutdown

. .

4

DB2

DB2PointDB2 Linux/Unix . .

Unix/Linux db2icrt u < FencedID > < InstName > db2icrt < InstName >

OS Platform . Owner Owner . OS

Owner .

Owner Owner

OS

. . .

Fenced User ID

Fenced User ID Fenced User ID

. .

Fenced User ID

.

1. root 2. User 3. (AIX

root . /home> su - root Owner Group . OS .) /> mkgroup db2iadm /> mkuser a pgrp=db2iadm db2inst1 /> mkgroup db2fadm /> mkuser a pgrp=db2fadm db2fenc1

Fenced . 1. Administrator . 2. DB2 ( c:program filesIBMsqllib .) bin db2cmd DB2 CLP . 3. db2icrt . c:/> db2icrt u db2fenc1 db2inst1 /

4. DB2 (AIX /opt/IBM/db2/V9.5 .) . 5. db2icrt /> db2icrt u db2fenc1 db2inst1

instance .

Fenced ID FencedID

Stored Procedure DB2 Engine Stored Procedure Stored Procedure

. OS

DB2 Engine . .

5

DB2

DB2PointDB2 Linux/Unix . .

1. 1 Administrator Ad i i t t 2. dbcmd 3. db2icrt

CLP .

. . CLP

DB2

DB2

SQL

.

Unix/Linux

1. root root . /home> su - root 2. Owner 3. OS /> mkgroup db2iadm /> mkuser a pgrp=db2iadm db2inst1 /> mkgroup db2fadm /> mkuser a pgrp=db2fadm db2fenc1 4. DB2 (AIX 5. db2icrt 5 db2i /> db2icrt u db2fenc1 db2inst1

Fenced User . (AIX

Group .)

.

/opt/IBM/db2/V9.5 .

.)

.

6

DB2

DB2PointUnix/Linux Linux/Unix . . .

1. db2ilist

.

3. list db database Name>" .

. drop database db2 catalog db amj on /home

test95

AMJ

.

test95

test95 . . .

AMJ

7

DB2

Point

.

.

DB2

,

DB2 Oracle SID = ORA11g DB Name = SAMPLE

SGA

sqlplus > CREATE DATABASE ORA11G LOGFILE GROUP 1( ~/ORADATA/log/redo01.log ) /ORADATA/log/redo01 log) SIZE 100M, GROUP 2( ~/ORADATA/log/redo02.log) SIZE 100M MAXLOGFILES 5 MAXLOGMEMBERS 5 DATAFILE $HOME/ORADATA/data/; sqlplus > conn / as sysdba;

db2=> CREATE DATABASE SAMPLE AUTOMATIC STORAGE YES ON C:,D db2=> UPDATE DB CFG FOR SAMPLE USING LOGPRIMARY 10 LOGSECOND 5 LOGFILSIZ 2000 NEWLOGPATH C:db2_logs LOGARCHMETH1 DISK:c:arch_logs db2=> CONNECT TO SAMPLE

SYSDBA : .

.

DB2 .

.

, SYSADM, : SYSCTRL

Oracle Database Configuration Assistant . CREATE DATABASE ~ .

DB2 GUI CREATE DATABASE~ .

. .

8

DB2

Point

.

DB2

.

DB2

(init.ora

) .

DB Configuration file .

DB2 archived redo log file ARCHIVEDLOG Mode redo log file

. OS

.

redo log file .

overwrite .

archived log file Archiving

redo log file .

overwrite .

. Control File : . integrity CREATE DATABASE ~ . control file . DB_CREATE_ONLINE_LOG_DEST_N OMF control file . . SQLSPCS.1 SQLSPCS.2 : . SQLOGCTL.LFH.1 SQLOGCTL.LFH.2 : active log . SQLDBCON SQLDBCONF : database configuration database SQLDBCONF SQLDBCON . db2rhis.asc db2rhist.bak : , , reorg history . DB2 . SQLBP.1 SQLBP.2 :

Data File Tablespace

. UNDO Tablespace, System Tablespace, Temporary Tablespace . DB_CREATE_FILE_DEST OMF data file .

container . Catalog Tablespace, User Space, Temporary Tablespace .

Log File Redo Log file : . Crash Recovery . Crash Recovery

9

DB2

/PointDB2 . .

OPEN

MOUNT

Activate Database

NOMOUNT

SHUTDOWN db2stop

db2start

DB2 SQL> startup nomount db2=> db2start . .

SQL> startup nomount SQL> alter database open SQL> startup

db2=> db2start db2=> activate database < DB >

.

SQL> startup restrict sqlplu> alter system enable RESTRICTED SESSION db2=> db2 > db2start admin mode RESTRICTED SESSION DB2 SYSADM, SYSMAINT, SYSCTRL .

.

DB2 SQL> shutdown db2> db2stop SQL> shutdown normal SQL> shutdown immediate db2> db2stop force . .

.

application

10

DB2

DB2PointDB2 .

1. , . , 3 DBMS . .

.

.

3.

.

.

.

.

4. DB2 . .

2.

.

11

DB2

DB2PointDB2 .

5.

.

7. .

Health Center

.

6.

SMTP

.

8.

.

12

DB2

Point

DB2

.

AIX

.

Create DB CREATE DATABASE C S CREATE Database : [ YES | NO ] ON

< DB Name>

CREATE Database b

AUTOMATIC STORAGE CATALOG TABLESPACE TEMPORARY TABLESPACE USER TABLESPACE AUTOCONFIGURE

[ path |drive ]

USING

Input

Value

APPLY

DB ONLY DB AND DBM NONE

: Input

.

workload_type tpm num_remote_apps :

simple, mixed, complex 1200 000 05 000

mixed 60 100

Simple CPU

I/O .

.

complex

.

. .

/home/inst95 > db2 db2 => create db amj automatic storage yes on /db2_data1,/db2_data2 DB20000I The CREATE DATABASE command completed successfully. Db2=> list db directory .

HR Schema Sdb2sampl EMPLOYEE, DEPARTMENT .

sample SAMPLE DATA

SAMPLE

. SAMPLE

13

DB2

Point

DB2

OS

.

DBMS

.

DB2

DB2 OS . db2set OS . DB2 Registry DB2 Registry DB2PATH, DB2INSTANCE . .

OS ORACLE_SID,ORACLE_BASE

. OS

DB2 PFILE : init.ora database initialization parameters . database initialization parameters OS Editor pfile . SPFILE : 9i parameters .

. Database Manager Configuration Database Configuration Database Configuration . SPFILE .

database initialization spfile.ora . spfile

.

pfile

pfile . spfile

SQL> show parameter [Parameter Name]

db2=> get dbm cfg db2=> get db cfg f f for db2=> update dbm cfg using < Parameter Name> < Value > db2=> update db cf g for < Database Name> using < Value > D f lt Default . db2=> reset dbm cfg db2=> reset db cfg for < Database Name>

SQL> alter system set = < Value > [ SCOPE=[MEMORY | SPFILE | BOTH ] ]

Default

Default . D f lt SQL> alter system reset < Parameter Name> [ SCOPE= MEMORY | SPFILE | BOTH ] SQL> startup /* SPFILE */

/home/inst32/db2start SQL>startup PFILE=initora10g.ora

14

DB2

Point

Configuration

Database Configuration File

init.ora .

DB2

Database Manager

Oracle 10g init.ora

DB2 9.5 : control file . DB2: SQLBP.1, SQLSPCS.1, SQLOG*, SQLDBCON, db2rhist.asc control . . pagesize i . .

control_files

db_nk_cache_size

: nK DB2: page size i * : DB2: Consistency :

db_block_checking

. page level integrity checksum page checking . .

db_block_checksum

checksum DB2: Consistency : control file DB2:

DBWn, ARCH, SQL*Loader . page level integrity checksum page checking .

block

.

db_create_online_log_ db create online log dest_n

newlogpathn (db cfg )

log file

Default .

.

: db_block_size pagesize (db cfg . ) DB2: Page Size . db_files maxtotfilop (dbm cfg ) DB2 : . : db_keep_cache_size Block . DB2: . : db_recycle_cache_size Block . DB2: DB2 LRU Recycle Pool . Recycle KEEP page size Default

15

DB2

Point

Configuration

Database Configuration File

init.ora .

DB2

Database Manager

Oracle 10g init.ora db_writer_processes

DB2 9.5 num_iocleaners (db cfg ) : Dirty Page . DB2 : Dirty Page . Container

dml_locks (locklist maxlock )

: . DB2 : DB2 lock Configuration

lock .

Database

java_pool_size

java_heap_sz (dbm cfg svcename (dbm cfg db2comm (registry )

DB2 )

: java app

.

local_listener

)

: Listener DB2 : Listener * . 5 : . DB2 :

. . SVCENAME DB2COMM .

Registry

log_archive_dest

logarchmeth1

TSM log_buffer logbufsz (db cfg maxcagents (dbm cfg sortheap p DB2 DB2 :

.

) )

.

sessions

: .

sort_area_size

: PGA DB2 : shared memory private memory .

.

16

DB2

DB2PointDB2 .

Registry DB2 DB2INSTANCE Default Client CLP . TCPIP CLP( sqlplus ) notepad, Unix . EDIT vi . . .

DB2_CLP_EDITOR

DB2_CLP_HISTSIZE Registry DB2COMM

.

TCPIP

Client

.

.

Registry

db2set lr

Registry ) C:> db2set lr Registry

.

.

db2set all

) C:>db2set all [e] DB2PATH=C:Program FilesIBMSQLLIB [i] DB2ACCOUNTNAME=KR010389db2admin [i] DB2INSTOWNER=KR010389 [i] DB2PORTRANGE=60000:60003 DB2PORTRANGE 60000 60003 [i] DB2COMM=TCPIP [g] DB2_EXTSECURITY=YES [g] DB2SYSTEM=KR010389 [g] DB2PATH=C:Program FilesIBMSQLLIB [g] DB2INSTDEF=DB2 [g] DB2ADMINSERVER=DB2DAS00 Registry . ) C:> db2set DB2COMM=TCPIP

db2set =

17

DB2

Point

.

Database Manager Configuration File

Database Configuration File

(

)

1.

=> .

DB2 sample

"db2cmd" SAMPLE

DB2 CLP

.

C:> db2start 2007-10-30 18:01:30 0 0 SQL1063N DB2START . SQL1063N DB2START . C:> db2sampl -sql C:>db2sampl Creating database "SAMPLE"... Connecting to database "SAMPLE"... Creating tables and data in schema "KR010389"... 'db2sampl' processing complete.

4. Database Manager Configuration . . SVCENAME 50000 . . .

2.

=> ,

=>

=> IBM DB2 => DB2COPY1( => < .

) => , . => 6. . 7. Database Configuration 1 2 . . MINCOMMIT . => SAMPLE

3.

DB2

> => .

) DB2

.

18

DB2

Point

.

1.

=>

=>

=> IBM DB2 => DB2COPY1( . DB2 2 .

)=>

4.

DB2INCLUDE

.

2. 2

3.

.

Registry

Registry

19

DB2

Point

.

Database Manager Configuration File

Database Configuration File

(

)

1. get dbm cfg C:LAB> db2 get dbm cfg | more C:LAB

(

)

.

3. get db cfg for . C:LAB> db2 get db cfg for amj | more C:LAB

amj = Enterprise Server Edition = 0x0c00 (MAXTOTFILOP) = 16000 CPU ( / )(CPUSPEED) = 3.700030e-007 (MB/ )(COMM_BANDWIDTH) = 1.000000e+002 (NUMDB) = 8 (FEDERATED) = NO (TP_MON_NAME) = Number Varchar2 = 0x0c00 = 0x0c00 = KR = 1208 = UTF-8 = 82 = IDENTITY (ALT_COLLATE) = = OFF = OFF = 4096 (DYN_QUERY_MGMT) = DISABLE (DISCOVER_DB) = ENABLE 2. update dbm cfg . = NO (DFT_QUERYOPT) (DFT QUERYOPT) = 5 (DFT_DEGREE) =1

/

SQL

C:LAB> db2 update dbm cfg using SVCENAME 50000 DB20000I UPDATE DATABASE MANAGER CONFIGURATION .

4. update db cfg for . C:LAB> db2 update db cfg for amj using LOGFILSIZ 2048 DB20000I UPDATE DATABASE CONFIGURATION .

get dbm cfg database manager configuration release level

.

.

.

get db cfg for . database code page, database code set, database country .

.

.

20

DB2

Point

.

Oracle Create Database ~ Temp

DB2 Create Database~ builds system, temp and user default tablespace db2start db2stop [force] update dbm cfg using update db cf g for using Default . reset dbm cfg reset db cfg for

startup pfile = ... shutdown [abort|...] alter system set < Parameter Name> = [ SCOPE=[MEMORY | SPFILE | BOTH ] ] Default Default . alter system reset < Parameter Name> [ SCOPE= MEMORY | SPFILE | BOTH ] SCOPE startup /* SPFILE */

/home/inst32/db2start startup PFILE=initora10g.ora Drop Database ~ including contents including contents .

Drop Database ~ ,

21

DB2

Q/AAIX Unix/Linux Platform Owner . DBI1131E User ID inst1is invalid OS . OS Owner . . ?

pfile

init.ora init ora . DB2

create prfile from spfile create spfile ? listener.ora . DB2 GUI , database manager import db2cfexp export .

PFILE tnsnames.ora , registry

Database Configuration File ? DB listen . . .

.

SQL1005N

. . list db directory .

?

IBM Corporation

IBM Corporation

Point.

.

DB2

DB2 DB2 TCPIP

Oracle N t O l Net

Middle-Tier Middl Ti .

. db2tcpcm

.

DB2 Oracle Net Listener . . db2tcpcm- TCPIP db2ipccm IPC db2snacm APPC . Listener.ora Net Manager . Net Configuration Assitant .

(TCPIP, IPC, IPX

)

(

)

. DBMS Configuration File Resistry Profile . .

Lsnrctl

Listener

.

DB2 N t Network k

. db2_local_ps . .

)

: LSNRCTL> start : LSNRCTL> stop

) db2start .

DB2

listener.ora Binary

Text

Editor / .

/ . DB2

.

2

DB2

Point.

.

A A4 Shared Memory Semaphore A1 A2 Logical Agent A3 DB2agent DB2agntpt A

DB2agntpt

DB2ipccm

DB2tcpcm B2 B B1 B3 B4

B DB2agntpt DB2agent DB2agntpt

B5

Idle Agent

DB2agent 2

A1. A2. DB2ipccm

DB2ipccm Coordinator Agent DB2agent EDU Shared Memory A Semophore . .

. .

B1. .

DB2tcpcm .

TCPIP

A3. DB2agent Agent A4.

DB2 Coordinator

B2. DB2tcpcm B3. Logical Agent Coordinator Agent B4. Coordinator Agent B5.

Agent DB2agent B

. . . .

3

DB2

PointDB2

Listen .

.

DB2

(

DB Name)

DB Name

. Net Manager tnsnames.ora Net Configuration Assistant . .

. . catalog catalog .

. Net Configuration Assistant tnsnames.ora

. . . . list node directory list db directory .

) ( . ) ( ) . (DB Name)

tnsnames.ora . Binary DB2 . sqllib/sqlnodir DB2 . DB2 Catalog

Text

Editor sqllib/sqlnodir/sqlnodir

,

/ .

sqllib/sqldbdir/sqldbdir

node directory

sqllib/sqldbdir/sqldbdir

db directory

4

DB2

Point

DB2 .

.

3 System DB Directory A connect to L_DB 1 1 1 Node Directory Node Name MYNODE 4 IP Addr 10.X.X.1 Port Num 3 50000 DB Alias DB Name Type L_DB R_DB DB1 DB1 remote MYNODE 2 Node C:db2 2 C:DB2

L_DB

Local DB Directory DB Alias L_DB DB Name DB1 Local

B connect to R_DB

R_DB

Local DB Directory DB Ali Alias R_DB DB N Name DB1

) : DB . Remote : DB . System db directory, local db directory, node db directory

MYNODE

.

. 1. System DB Directory ( ) 2. Type directory . 3. Local DB 3. 3 . 4. Directory . DB . tnsnames.ora Type Local DB 1. System DB Directory ( ) 2. Type .

. tnsnames.ora Type

.

.

Node Directory Local DB L l

5

DB2

Point

DB2 DB2 Catalog .

.

, . Local DB Directory Create Database ~ . , , DB2

,

listen

3

. drop Database~ . . PATH Drive> System DB Directory Local DB Directory . . . , , Local Database Directory Node Directory . System DB Directory System DB Directory . . IP Addr, Listen Port Node Directory node Directory . . Binrary . . . . . , on System DB Directory DB2 sqldbdir Node Directory DB2 sqllib/sqlnodir/sqlnodir list node directory list db directory

Catalog / Uncatalog System DB Directory , Node Directory , Node DB Listen / catalog catalog . .

System DB Directory Catalog System DB .

Local DB Directory . System db directory node directory

.

6

DB2

Point

.

1.

=>

=>

=> IBM DB2 => DB2COPY1( ) => . => < > => => DB2 .

4.

.

Listen

.

5.

.

.

6. 2. SQL22212N Admin instance "db2admin start"

.

DB2 .

.

C:LAB> db2admin start SQL4406W DB2 Administration Server d 3. . .

7. DB2

.

7

DB2

Point

.

1.

DB2COMM Profile Registry DB2 . C:LAB> db2set all [i] DB2COMM=TCPIP C:LAB> db2set DB2COMM= C:LAB> db2set DB2COMM=TCPIP C:LAB> db2set -all all [i] DB2COMM=TCPIP

3. .

DB2

C:LABUNIT5NET> db2stop [ force ] 2007-10-30 19:30:05 0 0 SQL1064N DB2STOP SQL1064N DB2STOP C:LABUNIT5NET> db2start 2007-10-30 19:30:05 0 0 SQL1064N DB2START SQL1064N DB2START . .

2. Database Manager Configuration . cfg cfg

DB2 .

Listen get dbm cfg update dbm

4. DB2

.

c:LAB> db2 get dbm cfg | find SVCENAME TCP/IP (SVCENAME) = db2c_DB2

c:LAB> db2 update dbm cfg using SVCENAME 50000 DB20000I UPDATE DATABASE MANAGER CONFIGURATION . SQL1362W . TERMINATE . DB2START .

Database Manager Configuration File D t b M C fi ti Fil Configuration Windows .

services i . services update dbm cfg using SVCENAME < > C:WINDOWSsystem32driversetc services

OS

. Listen . Unix/linux /etc services

8

DB2

Point

.

1.

=>

=>

=> IBM DB2 => DB2COPY1( =>

) => .

3.

"

"

.

. TCP/IP

2.

.

.

: :

. . export

IP

3

4. Port .

IP

OS

hosts

IP

.

:

IP

9

DB2

Point

.

5. SAMPLE

. . .

7.

.

.

8.

"

"

.

6. CLI/ODBC .

CLI/ODBC

10

DB2

Point

.

9. Kerberos . . Third-Party Security Default DBM

.

11.

DBM

ID OS

. ID

DBM

.

12.

.

,

10.

.

11

DB2

CATALOGPoint.

1. "list node directory" . . C:> db2 db2 => list node directory Node Directory Node name = NODENEO Directory entry type = LOCAL Protocol = TCPIP Hostname = 172.22.71.2 Service name = 50000

Node Directory uncatalog "list node directory"

5.

DB .

List DB Directory

) System DB Directory Directory . db2 => list db directory

Remote

= SAMPLE = NODENEO =

6. db2 => uncatalogp node NODNEO DB20000I UNCATALOG NODE DB21056W . . db2 => connect to

. > user < User ID> using

2. catalog .

Node Directory

Listen

7. Directory

DB

Uncatalog .

System DB .

db2 => catalog tcpip node remote < Server > server < Port port ) DB20000I CATALOG NODE DB21056W . . 8.

db2 => uncatalog node

Uncatalog . .

Node Directory

3. 3 )

List Node Directory Li t N d Di t local db directory .

. db2 => uncatalog db

4. Catalog DB Directory . DB2 .

System DB Directory DB DB Alias

DB

. System

db2 => catalog db < DB Name> as < Unique alias name > at node < Node Name> DB20000I CATALOG DB DB21056W . .

12

DB2

Q/ASQL30081N ping DB2 . . db2set all . get dbm cfg DB2COMM SVCENAME . . . DB2 DB2COMM Registry SVCENAME ? .

DB2

Connect

? OS . . . Default SERVER OS DBM CFG . AUTHENTICATION . Security Connect .

list db directory drop database directory .

. ? uncatalog system db directory . system db directroy t di t local db l l . catalog system db directory Local db directory catalog uncatalog drop .

IBM Corporation

IBM TSS Techline

IBM Corporation

Point

DB2

,

.

DB2

Database

Database

Table space

Datafile

Table space

Container

Segment

Object

Extent

Extent

Oracle Block

OS Page

DB2 Page

OS Page

Oracle

DB2 . Block (4k, 8k, 16k, 32k) . Block . . . DB2 .

DB2

Container

, ,

,

. . . Extent .

Extent

Extent

Block (2k, 4k, 8k, 16k, 32k)

PCT_FREE

Update

DB2

Datafile

Container

2

DB2

Point

.

.

DB2

.

DB2 Datafile . Container .

System Managed Space (SMS) Locally Managed Tablespace Extent . Free Extent Data Dictionary Managed Tablespace 8.15 8 15 Dictionary . . . . . Database Managed Space (DMS) Container Fil C i File R Raw Device D i Locally Managed Tablespace Automatic Storage Table Spaces DB2 SMS DMS . . . .

Regular . Temporary Join . Temporary Permanent Large UNDO Regular DMS 255 ) DB2 UNDO UNDO . SQL , Join . Temporary Temporary join User Temporary . . Undo UNDO . SQL Manager

.

.

UNDO

SYSTEM Data Dictionary TEMP

. . .

Temporary UNDOTBS1 UNDO USERS SYS, SYSTEM EXAMPLE

SYSCATSPACE Catalog Table . TEMPSPACE1 Temorary USERSPACE1 .

.

.

.

.

3

DB2

Point

,

,

.

DB2 CREATE TABLESPACE ALTER TABLESPACE . / Threshold Th h ld . CREATE TABLESPACE . DMS / PREFETCHSIZE, , / ,TRANSFERRATE / .

v$TABLESPACE

DBA_TABLESPACES .

SYSIBMADM.TBSP_UTILIZATION

.

DB2 : db2 => CREATE TABLESPACE amj_ts MANAGED BY DATABASE USING (FILE /tbs/amj_ts1.dbf 300M) : db2 => ALTER TABLESPACE amj_ts ADD ( file /tbs/amj_ts2.dbf 300M) : db2 => DROP TABLESPACE amj_ts : db2 => list tablespaces [ show detail ] db2 => SELECT tbsp_id as id, substr(tbsp_name,1,20), tbsp_type, tbsp_content_type, tbsp_state FROM SYSIBMADM.TBSP_UTILIZATION : db2 => list tablespace containers for [ show detail ] db2 => SELECT substr(tbsp_name,1,20), int(tbsp_id) as tid, substr(container_name,1,25) as cont_name, int(container_id) as cid, container_type, int(total_pages) as tot_pages FROM SYSIBMADM.CONTAINER_UTILIZATION WHERE tbsp_id = < ID>

: SQL> CREATE TABLESPACE amj_ts DATAFILE /tbs/amj_ts1.dbf SIZE 10M; : SQL> ALTER TABLESPACE amj_ts add DATAFILE /tbs/amj_ts2.dbf SIZE 10M; : SQL> DROP TABLESPACE amj_ts; : SQL> SELECT ts#,name FROM v$TABLESPACE; SQL>SELECT tablespace_name, extent_management, status, contents, block_size, allocation_type, segment_space_management FROM DBA_TABLESPACES; DBA TABLESPACES; : SQL> SELECT file#,status,block_size FROM v$DATAFILE; SQL> SELECT tablespace_name, file_name,file_id, status,increment_by FROM dba_data_files WHERE tablespace_name =< >;

4

DB2

DB2 DMS vs. SMSPointDB2 DMS SMS . .

DMS Tablespaces CREATE TABLESPACE dms PAGESIZE 8K MANAGED BY DATABASE USING ( file /db2/tbs/dms01 10M, file /db2/tbs/dms02 10M) EXTENTSIZE 16 ( /db2/tbs/dms01 RAW DEVICE ) :

SMS Tablespaces CREATE TABLESPACE sms PAGESIZE 8K C S C G S 8 MANAGED BY SYSTEM USING( /db2/tbs/sms01 , /db2/tbs/sms02) EXTENTSIZE 16 ( /db2/tbs/sms01/ ): SQLTAG.NAM SQL*.LF SQL*.LB SQL*.LBA SQL*.INX SQLTAG.NAM SQL*.LF SQL*.LB SQL*.LBA SQL*.INX

/db2/tbs/dms02

dms01 .

dms02

/db2/tbs/sms02/

SQLTAG.NAM : SQL*.LF : LONG VARCHAR, LONG VARGRAPHIC SQL*.LB : BLOB, CLOB, Q , , DBCLOB SQL*.LBA : SQL*.LB Free SQL*.INX :

DMS . Raw device AUTOMATIC . .

SMS

STORAGE . LOB . Extent

.

Page

.

.

. . DMS TEMPORARY SMS . . TEMPORARY .

5

DB2

DB2PointDB2

PAGESIZE

EXTENT SIZEExtent .

. . LONG VARCHAR, LONG VARGRAPHIC, BLOB, CLOB, DCLOB XML Descriptor . Table INLINE LENGTH Random . OLTP DSS PAGESIZE I/O PAGESIZE

.

Data Page

.

PAGESIZE/maximum Rows

.

PAGESIZE

.

/ /Page Size 4K 500 4005 DMS Storage Temporary Regular Automatic 64GB 8K 1012 8101 128GB 16K 1012 16293 256GB 32K 1012 32677 512GB

DMS Temporary temporary Automatic Storage LARGE (DB2 V9.7 ) DMS Temporary Temporary Automatic Storage LARGE (DB2 V9.7 )

2,048GB

4,096GB

8,192GB

1,6384GB

8,192GB

16,384GB

32,768GB

65,536GB

EXTENT

. DFT_EXTENT_SZ EXTENTSIZE

Container Extent

EXTENT .

num_ioservers . prefetchsize EXTENT . . . dft_prefetch_sz .

.

6

DB2

Point

DB2

.

Create Tablespace

CREATE

[ REGULAR | LARGE | SYSTEM TEMPORARY | USER TEMORARY ]

TABLESPACE

< TABLESPACE

>

PAGESIZE1 2 3

K EXTENTSIZE [K|M]

MANAGED BY AUTOMATIC STORAGE MANAGED BY SYSTEM MANAGED BY DATABASE PREFETCH SIZE AUTOMATIC

BUFFERPOOL

integer

[K|M]

1:

AUTOSIZE2:

[ YES | NO ]

INITIALSIZE

[ K | M | G]

INCREASESIZE

[ K | M | G]

,USING (3:

)

, USING ( [ FILE | DEVICE ] [ K | M | G] )

db2=> CREATE TEMPORARY TABLESPACE TEMPSPACE2 MANAGED BY DATABASE USING ('d:acc_tbsp', 'e:acc_tbsp') EXTENTSIZE 64 PREFETCHSIZE 32 db2=> CREATE TABLESPACE DATATS MANAGED BY AUTOMATIC STORAGE db2=> CREATE LARGE TABLESPACE LARGEDATA INCREASESIZE 10 PERCENT MAXSIZE 512 M db2=> CREATE TABLESPACE ACCOUNTING MANAGED BY DATABASE USING (FILE /tbs/acc_1' 50000, FILE /tbs/acc_2' 50000) EXTENTSIZE 256

7

DB2

Point

DB2

.

Alter Tablespace ALTER TABLESPACE ADD

< TABLESPACE2

>3] 3

[

|

[ EXTEND | REDUCE | RESIZE ] DROP ( [ FILE | DEVICE ]

)

,PREFETCH SIZE AUTOMATIC BUFFERPOOL [K|M]

integer

DROPPED TABLE RECOVERY )

[ YES | NO ] . .

Drop Tablespace DROP TABLESPACE

< TABLESPACE ,

>

db2=> ALTER TABLESPACE PAYROLL ADD (DEVICE '/dev/rhdisk9' 10000) db2=> ALTER TABLESPACE DATA_TS EXTEND (ALL 1000) db2=> ALTER TABLESPACE TS0 ADD (FILE 'cont2' 2000, FILE 'cont3' 2000) ADD (FILE 'cont4' 2000) EXTEND (FILE 'cont0' 100) RESIZE (FILE 'cont1' 3000) db2=> DROP TABLESPACE TS0

8

DB2

Point

LIST TABLESPACES

LIST TABLESPACES CONTAINERS .

SYSIBMADM.SNAPTBSP SYSIBMADM.TBSP_UTILIZATION SYSIBMADM.SNAPCONTAINER SYSIBMADM.CONTAINER_UTILIZATION

Snapshot Utilization Snapshot . Utilization

. .

.

SQL> SELECT SUBSTR(TBSP_NAME,1,30) AS TBSP_NAME, TBSP_ID, TBSP_TYPE, TBSP_CONTENT_TYPE FROM SYSIBMADM.SNAPTBSP; TBSP_NAME SYSCATSPACE TEMPSPACE1 USERSPACE1 TBSP_ID 0 1 2 TBSP_TYPE DMS SMS DMS TBSP_CONTENT_TYPE ANY SYSTEMP LARGE

------------------------------------------------------------------------------------------------------------------------------

SQL> SELECT TBSP_ID,SUBSTR(TBSP_NAME,1,15) AS TBSP_NAME, 2 TBSP_FREE_SIZE_KB,TBSP_PAGE_TOP, TBSP_AUTO_RESIZE_ENABLED 3 FROM SYSIBMADM.TBSP_UTILIZATION;

TBSP_ID 0 1 2

TBSP_NAME SYSCATSPACE TEMPSPACE1 USERSPACE1

TBSP_FREE_SIZE_KB 9,216 0 15,872

TBSP_PAGE_TOP BSP_AUTO_RESIZE_ENABLED 11,132 0 2,080 1 -1

----------------------------------------------------------------------------------------------------------------------------

SQL> SELECT SUBSTR(TBSP_NAME,1,20) AS TBSP_NAME, INT(TBSP_ID) AS TBSP_ID, 2 SUBSTR(CONTAINER_NAME,1,45) AS CONT_NAME, INT(CONTAINER_ID) AS CONT_ID, CONTAINER_TYPE SUBSTR(CONTAINER NAME 1 45) CONT NAME INT(CONTAINER ID) CONT ID CONTAINER TYPE 3 FROM SYSIBMADM.CONTAINER_UTILIZATION;

TBSP_NAME SYSCATSPACE TEMPSPACE1 USERSPACE1

TBSP_ID CONT_NAME 0 1 2 C:DB2NODE0000SAMPLET0000000C0000000.CAT C:DB2NODE0000SAMPLET0000001C0000000.TMP C:DB2NODE0000SAMPLET0000002C0000000.LR

CONT_ID 0 0 0

CONTAINER_TYPE FILE_EXTENT_TAG PATH FILE_EXTENT_TAG

--------------------------------------------------------------------------------------------------------------------------------------------------

9

DB2

Point

.

1.

db2cc

=> Sample => .

4. . .

.

2.

.

5. . .

. . Manager

3.

.

.

10

DB2

Point

.

6. Extent

.

Extent .

8.

.

9.

.

SQL

.

SQL

7.

SQL .

.

11

DB2

Point

.

1.

dms01

.

.

2.

.

12

DB2

Q/A. to write to a read-only file . OS . ? . SQL0970N system attempted

. SIZE ? 8K

? . .

. DB2 DB2 . . . OS

? .

INT, VARCHAR(100), VARCHAR(4000) . ERROR [42727] [IBM][DB2/LINUX] SQL0286N A default table space could not be found with a page size of at least "8192" that authorization ID "DB2" is authorized to use. SQLSTATE=42727 ? DB2 4K 8K . . . 8K 8K BLOB, CLOB . . 8K . LOB .

IBM Corporation

,

DB2 9.5 PL/SQL SQLPL

IBM Corporation

Point

DB2

.

. .

.

DB2

,

,

,

DB2

HR

HR

AMJ AMJ

DB2 . . . . SYS: SYSTEM: SAMPLE (HR, OE, PM, SH) . SYSIBM: SYSCAT: SYSSTAT: SYSFUN: CREATE SCHEMA < > AUTHORIZATION ~ : < >: : DROP SCHEMA < > RESTRICT

CREATE SCHEMA AUTHORIZATION < TABLE ~ : < >: .

> CREATE

. .

.

OWNER

.

dictionary DBA_TABLES ALL_TABLES .

.

SYSCAT.SCHEMATA

SQL> CREATE USER amj IDENTIFIED BY ***; SQL> CREATE SCHEMA AUTHORIZATION amj Q j CREATE TABLE AMJ.T1 ( C1 INT); SQL> select * from all_tables;

db2=> CREATE SCHEMA amj AUTHORIZATION HR db2=> CREATE TABLE AMJ.T1 ( C1 INT) ) db2=> list tables for schema < > db2=> select * from syscat.schemata

2

DB2

Point

.

DB2

.

DB2

. . . . LOB . , .

Multi Dimensional Clustering(MDC) . PCTFREE . DB2 . DMS . . . .

/ / DB2 . CREATE TABLE ~ / ALTER TABLE ~ / DROP TABLE ~ DBA_TABLES, DBA_TAB_COLUMNS schema < > . SYSCAT.TABLES, SYSCAT.COLUMNS . DESCRIBE TABLE [ ] list tables for list

.

DESC [

]

.

.

Dummy

DUAL . sqlplus > SELECT TO_CHAR(SYSDATE,YYYYMMDD) FROM DUAL;

SYSIBM.SYSDUMMY1 . db2 > db2=> SELECT TO_CHAR( CURRENT TIMESTAMP TO CHAR( ,YYYYMMDDHH24MISS) FROM SYSIBM.SYSDUMMY1;

DB2 CREATE VIEW view_name AS SELECT ALTER VIEW view_name ~ DROP View view_name DBA_VIEW . CREATE VIEW view_name AS SELECT ALTER VIEW view_name ~ DROP VIEW view_name SYSCAT.VIEW .

SQL> CREATE VIEW view01 AS SELECT ID,NAME FROM EMP; 3 DB2

db2=> CREATE VIEW view01 AS SELECT ID,NAME FROM EMP;

DB2 V9.7Point. DB2 , , , . . DB2

Oracle CHAR(n) VARCHAR2(n) LONG LONG CHAR(n) VARCHAR(n)

DB2 1

Column

: ALTER TABLE DEPARTMENT ADD COLUMN RATING CHAR(1); ALTER TABLE PROJECT ADD STTE_NOTES VARCHAR(1000) FOR BIT DATA; : ALTER TABLE EQUIPMENT ADD CONSTRAINT DEPTQUIP FOREIGN EY ( EQUIP_OWNER) REFERENCES DEPARTMENT ON DELETE SET NULL; CHECK : ALTER TABLE EMPLOYEE ADD CONSTRAINT REVENUE CHECK ( SALARY + COMM > 30000 ); : ALTER TABLE EMPLOYEE DROP CONSTRAINT REVENUE; : ALTER TABLE EMPLOYEE ALTER COLUMN WORKDEPT SET DEFAULT

123;

SECURITY Policy : ALTER TABLE EMPLOYEE ADD SECURITY POLICY DATA_ACCESS; SALARY EMPLOYEE : ALTER TABLE EMPLOYEE ALTER COLUMN SALARY SECURED WITH EMPLOYEESECLABEL;

12

DB2

Point

DB2

.

LIST TABLE

LIST

TABLES PACKAGES

FOR [ USER | ALL | SYSTEM | SCHEMA ] [

]

SHOW DETAIL

USER ALL SYSTEM SCHEMA [ ] .

. .

.

db2=> list tables for schema amj / ----------------------- -------------- ----SALES AMJ T

-------------------------2008-01-08-15.00.06.671000

db2=> list tables for system / ----------------------- -------------- ----- -------------------------ATTRIBUTES SYSCAT V 2007-11-27-14.25.58.609007 2007 11 27 14 25 58 609007 AUDITPOLICIES SYSCAT V 2007-11-27-14.25.58.843001 AUDITUSE SYSCAT V 2007-11-27-14.25.58.937003 BUFFERPOOLDBPARTITIONS SYSCAT V 2007-11-27-14.25.58.984003 BUFFERPOOLNODES SYSCAT V 2007-11-27-14.25.59.015003 BUFFERPOOLS SYSCAT V 2007-11-27-14.25.59.015007 CASTFUNCTIONS SYSCAT V 2007-11-27-14.25.59.031003 CHECKS SYSCAT V 2007 11 27 14.25.59.031007 2007-11-27-14 25 59 031007 COLAUTH SYSCAT V 2007-11-27-14.25.59.046003 -- More --

13

DB2

Point

.

DESC

.

DESCRIBE DESCRIBE [ TABLES | INDEXES FOR TABLE ] [ DATA PARTITIONS FOR TABLE ] DESCRIBE OUTPU T Select Call XQUERY XQUERY < Table > SHOW DETAIL

TABLE INDEXS FOR TABLE DATA PARTITIONS FOR TABLE .

.

.

db2=> describe table user1.departmentzzzz Table: USER1 DEPARTMENT T bl USER1.DEPARTMENT Column name -----------------AREA DEPT DEPTNAME Type Type schema name ----------- -----------------SYSIBM SMALLINT SYSIBM CHARACTER SYSIBM CHARACTER

Length -------2 3 20

Scale -------0 0 0

Nulls -------No No Yes

db2=> describe data partitions for table amj.sales show detail PartitionId ------------0 1 2 3 4 5 6 Inclusive (y/n) -----------------Y Y Y Y Y Y Y Low Value Inclusive (y/n) --------------- ----------------'2008-01-01' N '2008-02-01' N '2008-03-01' N '2008-04-01' N '2008-05-01' N '2008-06-01' N '2008-07-01' N High Value --------------'2008-02-01' '2008-03-01' '2008-04-01' '2008-05-01' '2008-06-01' '2008-07-01' '2008-08-01'

14

DB2

Point

.

1.

4. .

.

"

"

2.

"DB2ADMIN"

. 5. .

3.

.

.

15

DB2

Point

.

6.

. action . NULL .

. . . NULL . .

8. .

QUANTITY INTEGER

Null

. QUANTITY

.

1

9. 9 . 7. ITEM 20 . .

.

VARCHAR,

NULL

16

DB2

Point

10. . . LARGE .

. LOB

12.

.

.

13.

(Quantity (Q antit < 100)

. .

11. .

. .

.

14.

.

SQL

SQL

17

DB2

MDC +PointMDC .

+ MDC

CREATE TABLE AMJ.SALES ( DATE DATE NOT NULL , REGION VARCHAR(15) NOT NULL , PRODUCT_ID BIGINT NOT NULL , REVENUE DECIMAL(15,0) NOT NULL ) PARTITION BY RANGE("DATE") ( PART FY20081Q STARTING('2008-01-01') IN TBS1Q LONG IN LTBS1Q, PART FY20082Q STARTING('2008-04-01') IN TBS2Q LONG IN LTBS2Q, PART FY20083Q STARTING('2008-07-01') IN TBS3Q LONG IN LTBS3Q, PART FY20084Q STARTING('2008-10-01') ENDING('2009-01-01') EXCLUSIVE IN TBS4Q LONG IN LTBS4Q ) ORGANIZE BY ( ( "REGION" , "PRODUCT_ID" ) ) ;

CREATE UNIQUE INDEX AMJ.PARTITION_IDX ON AMJ.SALES ( DATE ASC ) INCLUDE ("REGION" ) NOT PARTITIONED IN DMS01 O O S0 PCTFREE 10 MINPCTUSED 10 ALLOW REVERSE SCANS; SELECT DATAPARTITIONNAME, TABSCHEMA, TABNAME, FROM SYSCAT.DATAPARTITIONS WHERE TABSCHEMA = AMJ AND TABNAME = SALES; > DATAPARTITIONNAME ----------------------------FY20081Q FY20082Q FY20083Q FY20084Q

TABSCHEMA ---------------AMJ AMJ AMJ AMJ

TABNAME LOWINCLUSIVE LOWVALUE HIGHINCLUSIVE HIGHVALUE ----------- ------------------- ---------------- -------------------- --------------SALES Y '2008-01-01 N '2008-04-01' SALES Y '2008-04-01 N '2008-07-01' SALES Y '2008-07-01' N '2008-10-01' SALES Y '2008-10-01 N '2009-01-01'

18

DB2

Point

DB2

.

RID

.

DB2 B+ Tree 64 UNIQUE NULL ALTER . Cluster Index Include . SYSCAT.INDEXES describe indexes for table < . . > show detail . . . . . NULL

B- Tree 32 UNIQUE NULL Clustered index IOT Index

. . . clustered Table NULL . .

DBA_INDEXES

.

DB2 CREATE INDEX IDX_SALES ON SALES (DATE ASC); DROP INDEX IDX_SALES; ALTER INDEX REBUILD; CREATE INDEX IDX_SALES ON SALES (DATE ASC); DROP INDEX IDX_SALES; ALTER INDEX .

19

DB2

Point

.

1.

.

.

4. .

.

"

DEPTNAME

2.

. 5. . .

3.

. 6. SQL SQL . .

20

DB2

Point

DB2

.

DB2 V9.7 < >.CURRVAL >.NEXTVAL . < PREVAL FOR < NEXTVAL FOR < > >

DB2 V9.7 .

.

DBA_SEQUENCES

.

SYSCAT.SEQUENCES

.

.

DB2

CREATE SEQUENCE ORDER_SEQ INCREMENT BY 1 START WITH 100 NO MAXVALUE NO CYCLE NOCACHE ; INSERT INTO ORDER_HIS VALUES ( ORDER_SEQ.NEXTVAL, BOOK, 100 ); SELECT ORDER_SEQ.CURRVAL FROM DUAL; DROP SEQUENCE ORDER_SEQ;

CREATE SEQUENCE ORDER_SEQ START WITH 100 INCREMENT BY 1 NO MAXVALUE NO CYCLE NOCACHE ; INSERT INTO ORDER_HIS VALUES ( NEXTVAL FOR ORDER_SEQ , BOOK, 100 ); SELECT PREVAL fOR ORDER_SEQ FROM SYSIBM.SYSDUMMY1; DROP SEQUENCE ORDER_SEQ;

21

DB2

DB2PointDB2 .

CREATE SEQUENCE START WITH

< >

>INCREMENT BY

AS INTEGER AS data-type

CYCLE

NO MIN VALUE MINVALUE < NO CACHE CACHE < : > >

NO MAXVALUE MAXVALUE < NO ORDER ORDER .

AS < data-type> START WITH INCREMENT BY MINVALUE MAXVALUE CYCLE CACHE :

SMALLINT, INT, BIGINT, DECIMAL . . . . .

.

. .

Select * from ORDER; CREATE SEQUENCE order_seq START WITH 100 INCREMENT BY 1 NO MAXVALUE NO CYCLE CACHE 24 INSERT INTO ORDER VALUES ( nextval for order_seq , PAPER BAG ); INSERT INTO ORDER VALUES ( nextval for order_seq ,NOTE ); ORDER_NUM 100 101 ORDER_NAME PAPER BAG NOTE

Select preval for order_seq FROM SYSIBM.SYSDUMMY1; 1 101

22

DB2

Point

INSERT, UPDATE, DELETE

.

DB2 V9.7 . . BEFORE, AFTER . . BEFORE, AFTER . REPLACE PLSQL . REPLACE . .

DB2 V9.7

. BEFORE, AFTER .

INSERT, UPDATE, DELETE

INSERT, UPDATE, DELETE

INSERT, UPDATE, DELETE

DB2 CREATE TRIGGER con_audit_trg CREATE OR REPLAC E TRIGGER con_audit_trg BEFORE INSERT ON CON_AUDIT FOR EACH ROW BEGIN :new.timestamp := SYSDATE; END; CREATE OR REPLAC E TRIGGER con_audit_trg BEFORE INSERT ON CON_AUDIT FOR EACH ROW BEGIN :new.timestamp := SYSDATE; END; CREATE TRIGGER emp_history_trg AFTER DELETE ON employees FOR EACH ROW BEGIN INSERT INTO emp_history( emp_id , first_name , last_name ) VALUS ( :old.emp_id ,:old.first_name,:old.last_name ); END; NO CASCADE BEFORE INSERT ON CON_AUDIT REFERENCING NEW as n FOR EACH ROW MODE DB2SQL BEGIN ATOMIC SET n.timestamp = CURRENT TIMESTAMP; END! CREATE TRIGGER con_audit_trg NO CASCADE BEFORE INSERT ON CON_AUDIT REFERENCING NEW as n FOR EACH ROW BEGIN ATOMIC SET n.timestamp = CURRENT TIMESTAMP; END! CREATE TRIGGER emp_history_trg AFTER DELETE ON EMPLOYEES REFERENCING OLD as d FOR EACH ROW BEGIN ATOMIC INSERT INTO emp_history ( emp_id , first_name , last_name ) VALUES ( d.emp_id ,d.first_name,d.last_name ); END!

23

DB2

Point

.

1.

.

.

3.

.

.

SQL

"old"

2.

EMPLOYEE .

"staff_del_trg" " " "

KR010389 "

.

24

DB2

DB2 V9.7PointUser Defined Function(UDF) . . . Stored Function DB2 .

DB2 Boolean . .

JAVA

C

JAVA . .

C

OLE DB Provider

CREATE [ OR REPLACE ] FUNCTION func_name [( [ IN | OUT ] datatype [ DEFAULT value] [ , .. ] ) ] RETURN datatype [ PIPELINED ] { IS | AS } SQL /

CREATE FUNCTION func_name [( datatype ( size ) [ , .. ] ) ] RETURN { Scalar_return_data_type | TABLE ( column_list) } LANGUAGE SQL [ READ SQL DATA | CONTAINS SQL ] SQL @

sql> CREATE OR REPLACE FUNCTION test01 (x number DEFAULT 1000 ) RETURN number IS BEGIN RETURN ( 0.5 * x * x * 3.14 ) ; END; /

db2=> CREATE FUNCTION test01 (x numeric(10,2) ) RETURNS numeric(10,2) LANGUAGE SQL BEGIN ATOMIC RETURN ( 0.5 * x * x * 3.14 ) ; END@

@a.sql @a sql . SQL "db2 td! vf"

.

SQL DB2

. ( @ . ) ! SQL .

25

DB2

DB2 V9.7PointDB2 V9.7 Syntax Syntax . .

DB2 Boolean . .

JAVA

C

JAVA . .

C

OLE DB Provider

CREATE [ OR REPLACE ] FUNCTION func_name [( [ IN | OUT ] datatype [ DEFAULT value] [ , .. ] ) ] RETURN datatype [ PIPELINED ] { IS | AS } SQL /

CREATE [ OR REPLACE ] FUNCTION func_name [( [ IN | OUT ] datatype [ DEFAULT value] [ , .. ] ) ] RETURN datatype [ PIPELINED ] { IS | AS } SQL /

sql> CREATE OR REPLACE FUNCTION test01 ( (x number DEFAULT 1000 ) RETURN number IS BEGIN RETURN ( 0.5 * x * x * 3.14 ) ; END; /

db2=> CREATE OR REPLACE FUNCTION test01 (x ( number DEFAULT 1000 ) b RETURN number IS BEGIN RETURN ( 0.5 * x * x * 3.14 ) ; END;

DB2 V9.7

PL/SQL

.

26

DB2

Point

.

DB2 ABS FLOOR MOD POWER N/A ROUND(arg1,arg2) TRUNC(n[,m]) LEAST GREATEST CEIL ABS FLOOR MOD POWER RAND ROUND(arg1,arg2) TRUNC (n[,m]) LEAST GREATEST CEIL Argument Argument Argument . . . . . argument Argument . argument Argument . . . .

DB2 sql> SELECT ABS(-2) FROM DUAL; ABS(-2) 2 sql> SELECT ROUND(45.926,2) FROM DUAL; q ( , ) ; ROUND ( 45.926,2) 45.93 sql> SELECT TRUNC(45.926,2) FROM DUAL; ROUND ( 45.926,2) 45.92 sql> SELECT MOD(1600,300) FROM DUAL; MOD(1600 300) MOD(1600,300) 100 sql> SELECT CEIL(13.11) FROM DUAL; CEIL(13.11) 14 db2=> VALUES RAND() 1 +1.25125888851588E-003 1 14. 1 100 db2=> SELECT CEIL(13.11) FROM SYSIBM.SYSDUMMY1 1 45.920 db2=> VALUES MOD(1600,300) MOD(1600 300) 1 45.930 db2=> VALUES TRUNC(45.926) db2=> SELECT ABS(-2) FROM SYSIBM.SYSDUMMY1 1 2 db db2=> VALUES ROUND(45.926,2) U S OU ( 5 9 6, )

27

DB2

Point

.

DB2 V9.7 ASCII CHR(n) CONCAT N/A INITCAP INSTR LENGTH / LENGTHB /LENGTHC LOWER LPAD(arg1,arg2,arg3) RPAD(arg1,arg2,arg3) LTRIM / RTRIM TRIM REPLACE(arg1,arg2,arg3) SUBSTR TRANS