0% found this document useful (0 votes)
42 views19 pages

Course Materials May Not Be Reproduced in Whole or in Part Without The Prior Written Permission of IBM

modul database

Uploaded by

Bagus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views19 pages

Course Materials May Not Be Reproduced in Whole or in Part Without The Prior Written Permission of IBM

modul database

Uploaded by

Bagus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Introduction

© Copyright IBM Corporation 2010, 2013


Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 7.0
Unit objectives
After completing this unit, you should be able to:
• Define the terms:
– Database, table, row, column, view
• State the more common DB2 data types
• List the most commonly used SQL statements in the:
– Data Definition Language (DDL)
– Data Manipulation Language (DML)
– Data Control Language (DCL)
• State three null characteristics, and their meaning

© Copyright IBM Corporation 2010, 2013


Relational Database Management System
(RDBMS)

EMPLOYEE DEPARTMENT
MID WORK DEPT DEPTNAME
EMPNO FIRSTNME LASTNAME ... ...
INIT DEPT NO
000010 CHRISTINE I HAAS A00 A00 SPIFFY COMPUTER SERVICE DIV.

000020 MICHAEL L THOMPSON B01 B01 PLANNING

000030 SALLY A KWAN C01 C01 INFORMATION CENTER

000050 JOHN B GEYER E01 D01 DEVELOPMENT CENTER

000060 IRVING F STERN D11 D11 MANUFACTURING SYSTEMS

000070 EVA D PULASKI D21 D21 ADMINISTRATION SYSTEMS

PROJECT
DEPT
PROJNO PROJNAME NO ...

Database AD3100 ADMIN SERVICES D01


A collection of AD3110 GENERAL ADMIN SYSTEMS D21
tables
AD3111 PAYROLL PROGRAMMING D21

AD3112 PERSONNEL PROGRAMMING D21

AD3113 ACCOUNT PROGRAMMING D21

IF1000 QUERY SERVICES C01

© Copyright IBM Corporation 2010, 2013


Asking for information: RDBMS

Return a list of RDBMS


employees in EMPLOYEE
department D11 EMPNO LASTNAME
MID
FIRSTNME WORKDEPT PHONENO
INIT
sorted by last name
000150 ADAMSON BRUCE D11 4510

000200 BROWN DAVID D11 4501

000050 GEYER B JOHN E01 6789

000340 GOUNOT R JASON E21 5698

000010 HAAS T CHRISTINE A00 3978

SELECT * FROM
EMPLOYEE WHERE
WORKDEPT = 'D11'
ORDER BY LASTNAME
SE L E
CT S
tatem
ent

© Copyright IBM Corporation 2010, 2013


SQL Structured Query Language

COMMIT

ROLLBACK

© Copyright IBM Corporation 2010, 2013


Table
EMPLOYEE

EMPNO FIRSTNME MIDINIT LASTNAME . . . BIRTHDATE SALARY

000010 CHRISTINE I HAAS . . . 1933-08-24 9220

000020 MICHAEL L THOMSON . . . 1948-02-02 0

row 000030 SALLY A KWAN . . . 1941-05-11 -----

000050 JOHN B GEYER . . . 1925-09-15 3214

..... ..... ..... ..... ... ..... .....

000330 WING LEE . . . 1941-07-18 2030

column text column date column numeric


column
© Copyright IBM Corporation 2010, 2013
Table names in DB2

Simple Table Name Seattle

 PARTS
Chicago

Qualified Table Name Atlanta


 PROD. PARTS

Fully-Qualified Table Name

 ATLANTA.PROD. PARTS

© Copyright IBM Corporation 2010, 2013


Names

First character
Every table and must be:
every column A-Z, $, @, #
must be named Remaining:
A-Z, $, @, #, 0-9, _

Table name
Column
unique to
names
owner/schema
unique to
table

© Copyright IBM Corporation 2010, 2013


Sample Numeric data types

Data Type Comment

SMALLINT Whole numbers from -32768 to +32767

INTEGER Whole numbers from -2,147,483,648 to


+2,147,483,647

BIGINT Whole numbers from -8 XB to +8 XB


XB = exabytes, 2 raised to the 60th power

DECIMAL(p,s) Decimal numbers


p = precision (total number of digits)
s = scale (number of decimal digits)
© Copyright IBM Corporation 2010, 2013
Sample Alphanumeric data types

Data Type Comment

CHAR(n) or STRING (fixed length)


CHARACTER(n)

VARCHAR(n) STRING (variable length)

© Copyright IBM Corporation 2010, 2013


DB2 DATE data type

Data Type Comment

DATE Display / Input Format


YYYYMMDD USA mm/dd/yyyy
EUR dd.mm.yyyy
ISO yyyy-mm-dd
JIS yyyy-mm-dd

DATE / TIME / TIMESTAMP data types - input verification


allows arithmetic
sorting
component extraction
© Copyright IBM Corporation 2010, 2013
DB2 TIME and TIMESTAMP data types

Data Type Comment

TIME Display / Input Formats


HHMMSS USA hh:mm AM or PM
EUR hh.mm.ss
ISO hh.mm.ss
JIS hh:mm:ss

TIMESTAMP Display / Input Format


YYYYMMDDHHMMSSXXXXXX yyyy-mm-dd-hh.mm.ss.xxxxxx
where xxxxxx = microseconds

© Copyright IBM Corporation 2010, 2013


CREATE TABLE

CREATE TABLE EMPLOYEE


( EMPNO CHAR(6) NOT NULL,
FIRSTNME VARCHAR(12) NOT NULL,
MIDINIT CHAR(1) NOT NULL,
LASTNAME VARCHAR(15) NOT NULL,
WORKDEPT CHAR(3) ,
. . .
. . .
BIRTHDATE DATE ,
SALARY DECIMAL(9,2) ,
BONUS DECIMAL(9,2) ,
COMM DECIMAL(9,2) )
© Copyright IBM Corporation 2010, 2013
NULL characteristics

"nullable" Column can be marked as having


an 'unknown value'

NOT NULL Column must always have a value

NOT NULL WITH Column must always have a value


DEFAULT if we do not supply one, a system
or user-defined default value will be
supplied

© Copyright IBM Corporation 2010, 2013


Authorization

GRANT SELECT ON PROJECT TO SALLY

DEPARTMENT

PROJECT
EMPLOYEE

REVOKE SELECT ON PROJECT FROM SALLY


© Copyright IBM Corporation 2010, 2013
VIEW

You only see what you should  Data security

EMPNO FIRSTNME MIDINIT LASTNAME WORKDEPT PHONENO

000150 BRUCE ADAMSON D11 4510

000200 DAVID BROWN D11 4501

000050 JOHN B GEYER E01 6789

000340
JASON R GOUNOT E21 5698

000010 CHRISTINE T HAAS A00 3978

 Data independence  Simplification


© Copyright IBM Corporation 2010, 2013
Checkpoint

1. True or False? A database is a collection of tables.

2. What are some of the advantages of using DATE data


types?

3. Name the alphanumeric and numeric data types covered in


this unit.

4. Name the types of SQL statements in the Data


Manipulation Language (DML).

© Copyright IBM Corporation 2010, 2013


Checkpoint solutions
1. True
2. Automatic verification of correctness
Date arithmetic
Date, time, timestamp sorting
Extraction of components
3. CHAR (fixed length)
VARCHAR (variable length)
SMALLINT
INTEGER
BIGINT
DECIMAL(p,s)

4. SELECT
INSERT
UPDATE
DELETE

© Copyright IBM Corporation 2010, 2013


Unit summary
Having completed this unit, you should be able to:
• Define the terms:
– Database, table, row, column, view
• State the more common DB2 data types
• List the most commonly used SQL statements in the:
– Data Definition Language (DDL)
– Data Manipulation Language (DML)
– Data Control Language (DCL)
• State three null characteristics, and their meaning

© Copyright IBM Corporation 2010, 2013

You might also like