This document outlines an agenda for a presentation on DB2 objects and SQL-PL. It discusses various DB2 concepts like data types, buffer pools, tablespaces, tables, stored procedures, functions, views, triggers, and the system catalog. It also describes several labs that will have attendees create and manage DB2 objects and write SQL-PL code. The goal is to provide fundamental knowledge on working with DB2 objects and the SQL procedural language.
2. 2
Agenda
• Data Type
• Buffer Pool
• Tablespaces
• Table
• SQL-PL
• SYSCAT
• Schema
• Procedure
IBM DB2 9.1 Fundamental Presentation
DB2 Objects and SQL-PL presented by Fuangwith S.
3. 3
Agenda (Cont.)
• Function
• View
• Trigger
IBM DB2 9.1 Fundamental Presentation
DB2 Objects and SQL-PL presented by Fuangwith S.
4. 4
DB2’s Data Type
IBM DB2 9.1 Fundamental Presentation
DB2 Objects and SQL-PL presented by Fuangwith S.
5. 5
Interesting Data Type
IBM DB2 9.1 Fundamental Presentation
Data Type Min Max
CHARACTER 1 255
VARCHAR 1 32704
SMALLINT -32768 +32767
INTEGER or INT -2147483648 +2147483647
BIGINT -9223372036854775808 +9223372036854775807
DECIMAL or NUMERIC 1 - 10³¹ 10³¹ - 1
DATE 0001-01-01 12/31/9999
TIME 00.00.00 24.00.00
TIMESTAMP 0001-01-01-00.00.00.000000 9999-12-31-24.00.00.000000
DB2 Objects and SQL-PL presented by Fuangwith S.
6. 6
Tablespaces and Buffer Pools
IBM DB2 9.1 Fundamental Presentation
DB2 Objects and SQL-PL presented by Fuangwith S.
7. 7
LAB I
• Create Buffer Pools
• Create Tablespaces
• Create Table
• Drop Table
• Alter Table
IBM DB2 9.1 Fundamental Presentation
DB2 Objects and SQL-PL presented by Fuangwith S.
8. 8
SQL-PL
IBM DB2 9.1
SQL-PL
PL/SQL r a
IBM DB2 9.1 Fundamental Presentation
IBM DB2 9.7
SQL-PL
PL/SQL a
a
DB2 Objects and SQL-PL presented by Fuangwith S.
9. 9
System Catalog
IBM DB2 9.1 Fundamental Presentation
• Schema SYSCAT
• example
– SYSCAT.TABLES
– SYSCAT.TABLESPACES
– SYSCAT.COLUMNS
– SYSCAT.VIEWS
– and etc.
SQL0407N Assignment of a NULL value to a NOT NULL column
"TBSPACEID=3, TABLEID=27, COLNO=3" is not allowed. SQLSTATE=23502
DB2 Objects and SQL-PL presented by Fuangwith S.
10. 10
SQL - 407
IBM DB2 9.1 Fundamental Presentation
SELECT
TBS.TBSPACE,
TAB.TABNAME,
COL.COLNAME
FROM
SYSCAT.TABLESPACES AS TBS
INNER JOIN SYSCAT.TABLES AS TAB
ON TBS.TBSPACEID =
TAB.TBSPACEID
INNER JOIN SYSCAT.COLUMNS AS COL
ON TAB.TABNAME = COL.TABNAME
WHERE
TBS.TBSPACEID = 3
AND TAB.TABLEID = 27
AND COL.COLNO = 3;
DB2 Objects and SQL-PL presented by Fuangwith S.
11. 11
LAB II
• Create Stored Procedure
• Drop Stored Procedure
IBM DB2 9.1 Fundamental Presentation
DB2 Objects and SQL-PL presented by Fuangwith S.
12. 12
LAB III
• Function
• View
• Trigger
IBM DB2 9.1 Fundamental Presentation
DB2 Objects and SQL-PL presented by Fuangwith S.
13. 13
TOMORROW
IBM DB2 9.1 Fundamental Presentation
• Global Temporary Table (GTT)
• Catch Exception
• Signal
• ‘LIKE’ predicate
• Basic Locking
DB2 Objects and SQL-PL presented by Fuangwith S.