db2 appl day 1

Upload: johnfelixpaul05

Post on 29-May-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 DB2 Appl Day 1

    1/57

    Introduction to DB2

  • 8/8/2019 DB2 Appl Day 1

    2/57

    DB2 is an abbreviation for IBM DATABASE2

    DB2 is a subsystem of the z/OS OperatingSystem

    It is a database management system(DBRM)

    It is a system that allows any number ofz/OS users to access any number of relational

    databases by means of the well-knownrelational lan ua e SQL

  • 8/8/2019 DB2 Appl Day 1

    3/57

    W h a t is D a ta a n dIn fo rm a tio n

    Information is nothing but refined data andis the backbone of an organization.

    Consists of Data

    Images

    Documents

    Even voice

  • 8/8/2019 DB2 Appl Day 1

    4/57

  • 8/8/2019 DB2 Appl Day 1

    5/57

    What is Relation?

    Relation is just a mathematical term fora table.

    Relational systems are based on what iscalled the relational model of data

    The principles of the relational modelintroduced by Dr. E F Codd IBMresearcher.

    All the RDBMS follows CODD's RELATIONAL RULES

    12 rules

  • 8/8/2019 DB2 Appl Day 1

    6/57

    Terms we use in DB2

    Table , Record , Row , Field ,Column and Primary Key

    We use the terms Record andRow interchangeably

    and the terms Field and Columnlikewise

  • 8/8/2019 DB2 Appl Day 1

    7/57

  • 8/8/2019 DB2 Appl Day 1

    8/57

  • 8/8/2019 DB2 Appl Day 1

    9/57

    H IE R A R C H IC A L

    To p d o w n stru ctu re re sem b lin g a n-u p sid e d o w n tre e

    Pa re n t ch ild re la tio n sh ip First lo g ica ld a ta b a se m o d e l

    A va ila b le o n m o st o f th e M a in fra m e

    com puters E xam ple IM S

  • 8/8/2019 DB2 Appl Day 1

    10/57

    N E T W O R K

    D oe s n ot d istin g u ish b e tw e en p aren t a n d.ch ild A n y re cord typ e can b e a sso cia te d

    w ith a n y n u m b e r o f a rb itra ry re co rd typ e s -E xa m p le ID M S

  • 8/8/2019 DB2 Appl Day 1

    11/57

    Primary Key

    Key which uniquely identifies each row in thetable

    Candidate key

    Set of attributes which uniquely identify the row

    Alternate key

    Remaining candidate key that were not chosen asprimary key

    Foreign key

    An attribute of one table can be the primary keyof another table

  • 8/8/2019 DB2 Appl Day 1

    12/57

    S T R U C T U R E D Q U E R Y LA N G U A G E

    In tro d u ctio n

    C h a ra cte ristics a n d C o m p o n e n ts

    Types

  • 8/8/2019 DB2 Appl Day 1

    13/57

    In tro d u ctio n

    ,C o n sists o f se t o f fa cilitie s fo r d e fin in g

    a cce ssin g a n d m a n a g in g re la tio n a l

    .d a ta b a ses ,S Q L ca n b e in vo ke d e ith e r in te ra ctive ly o r

    b y e m b e d d in g th e m in a p p lica tio n

    .program s

    V e ry flexib le

  • 8/8/2019 DB2 Appl Day 1

    14/57

    A d v a n ta g e s o f S Q L

    Pro vid e s g re a te r d e g re e o f a b stra ctio n

    .th a n p ro ced u ra lla n g u a g e s

    -E n a b le s e n d u sers to d e a lw ith m u ltip le.n u m b e r o f d a ta b a se s at th e sa m e tim e

    S p e cifie s w h a t is re q u ire d a n d n o t h o w it

    .sh ou ld b e d on e

  • 8/8/2019 DB2 Appl Day 1

    15/57

    U se s o f S Q L

    Q u e ry

    D efin itio n o f d a ta stru ctu re s

    C o n tro llin g a cce ss to th e d a ta

    /D e le te M o d ify o ccu rre n ce s o f th e d a ta .

  • 8/8/2019 DB2 Appl Day 1

    16/57

    SQL (User Application Programming or Intera

    View I View II

    Virtual

    Base Table1

    Base Table2

    Base Table3

    Base Table4

    Real

    VSAMLDS

    VSAMLDS

    VSAMLDS

    VSAMLDS

    Stored

  • 8/8/2019 DB2 Appl Day 1

    17/57

    -DB2 Data Types

  • 8/8/2019 DB2 Appl Day 1

    18/57

    -DB2 Data Types

    ( )Char n <

  • 8/8/2019 DB2 Appl Day 1

    19/57

    String Data type

  • 8/8/2019 DB2 Appl Day 1

    20/57

    Numeric Data type

  • 8/8/2019 DB2 Appl Day 1

    21/57

    Numeric Data type

  • 8/8/2019 DB2 Appl Day 1

    22/57

  • 8/8/2019 DB2 Appl Day 1

    23/57

    DB2 Components

    DDL Data Definition Language

    DML Data Manipulation Language

    DCL Data Control Language

    Retrieval Selects the data from the table

  • 8/8/2019 DB2 Appl Day 1

    24/57

    DDL

    Create Create schema objects

    Alter Alter Schema objects

    .Drop Delete schema objects

    .Rename Rename the schema object

  • 8/8/2019 DB2 Appl Day 1

    25/57

    DML

    Insert Add new rows into the table

    Update Modify values in the existing rows

    Delete Removing already existing rows

  • 8/8/2019 DB2 Appl Day 1

    26/57

    DCL

    Grant Grant privileges and roles

    .Revoke Take away privileges

  • 8/8/2019 DB2 Appl Day 1

    27/57

  • 8/8/2019 DB2 Appl Day 1

    28/57

    DDL

    CREATE TABLE

    CREATE INDEX

    ALTER TABLE CREATE VIEW

    ,DROP TABLE VIEW AND INDEX

  • 8/8/2019 DB2 Appl Day 1

    29/57

    Create Table

    CREATE TABLE (column1 (data type) NULL/NOT NULL

    PRIMARY KEY,

    column2 (data type), . )

    IN DATABASE.TABLESPACE;

  • 8/8/2019 DB2 Appl Day 1

    30/57

    What is NULL?

    NULL means that the value of thatfield (column) is unknown.

    NOT NULL means guarantee thatevery column (field) contain agenuine value

    NOT NULL WITH DEFAULT means thatfield (column) cannot contain nulls(unknown values)

  • 8/8/2019 DB2 Appl Day 1

    31/57

    NOT NULL WITH DEFAULT

    DB2 automatically moves thefollowing values

    Zero (0) for Numeric Field

    Blanks (spaces) for Alphanumeric orAlpha

  • 8/8/2019 DB2 Appl Day 1

    32/57

    In te ra ctin g D B 2 w ith S P U FI

    Now we will discuss about how tocommunicate with DB2 with SPUFI

    In ISPF panel choose option 8 for DB2 as

    follows

    How to execute SQL with SPUFI

  • 8/8/2019 DB2 Appl Day 1

    33/57

    How to execute SQL with SPUFIStep 1

    Login to TSO region

    Step 2

    .Select 8 1 option in ISPF main menu

    Step 3

    Specify the Input dataset and Output Dataset for the SQL Queryand result of the Query

    Step 4

    Now Give the SQL query for executing

    Step 5;;;Type END for execution of the query

  • 8/8/2019 DB2 Appl Day 1

    34/57

    Select option 8 for

  • 8/8/2019 DB2 Appl Day 1

    35/57

    Select option 1 for( )or

    .Type 8 1 option directly i

  • 8/8/2019 DB2 Appl Day 1

    36/57

    Type the Input da( )PDS Data Set

    (Type the output dataset name PS

  • 8/8/2019 DB2 Appl Day 1

    37/57

    Give the settings as per our requirement then

  • 8/8/2019 DB2 Appl Day 1

    38/57

    Give the queries to be exec

    ;;;Type END for execution of

  • 8/8/2019 DB2 Appl Day 1

    39/57

  • 8/8/2019 DB2 Appl Day 1

    40/57

    DB2 Queries DEMO

    CREATE TABLE

  • 8/8/2019 DB2 Appl Day 1

    41/57

    CREATE TABLESYNTAX:CREATE TABLE (column1 data type NULL/NOT NULL PRIMARY KEY, column2 data type, . ) IN DATABASE.TABLESPACE;

    Result of CREATE TABLE

  • 8/8/2019 DB2 Appl Day 1

    42/57

    Result of CREATE TABLE

    =SQLCODE 0 means Success< ( . .. - , - ,)0 means Error E g 104 181> ( . .. + )0 means Warning E g 100

  • 8/8/2019 DB2 Appl Day 1

    43/57

    INSERT (ing) values into the table

    Syntax 1:INSERT INTO Values ( col1_value, col2_Value,)

    Use this syntax when you are giving values for all the

    fields

    Syntax 2:INSERT INTO [(Col3,col5,..) ] Values ( Col3_value, Col5_Value,)

    Use this syntax when you want to give value forspecific fields

  • 8/8/2019 DB2 Appl Day 1

    44/57

  • 8/8/2019 DB2 Appl Day 1

    45/57

    SQLCODE = 0 successful Insertion

  • 8/8/2019 DB2 Appl Day 1

    46/57

    SELECT rows from Table

    SELECT is the statement that retrieves the recordsfrom the table.

    Syntax:

    SELECT FROM

    {WHERE } - optional

    {GROUP BY } - optional

    {HAVING } - optional

    Complete syntax oOptional clause will be

  • 8/8/2019 DB2 Appl Day 1

    47/57

    SELECT rows from Table

    * ;S E LE C T FR O M E M P*H e re re fe rs to a ll th e co lu m n s

    = +SQLCODE 100 means end of table or no mor

  • 8/8/2019 DB2 Appl Day 1

    48/57

    Let us now CREATE Table with PrimaryKey

    Primary key columnhave unique value and it should be NOT NULL which provides a way

  • 8/8/2019 DB2 Appl Day 1

    49/57

    Result of query is success

  • 8/8/2019 DB2 Appl Day 1

    50/57

  • 8/8/2019 DB2 Appl Day 1

    51/57

    CREATE UNIQUE INDEX

  • 8/8/2019 DB2 Appl Day 1

    52/57

    CREATE UNIQUE INDEX

    :S yn ta x< >C R E ATE U N IQ U E IN D EX in d ex n am e

    n a m e

    CREATE UNIQUE INDEX lt

  • 8/8/2019 DB2 Appl Day 1

    53/57

    CREATE UNIQUE INDEX result

    f l

  • 8/8/2019 DB2 Appl Day 1

    54/57

    After UNIQUE INDEX, now let us INSERTvalues

  • 8/8/2019 DB2 Appl Day 1

    55/57

    INSERT Success

    L CREATE h bl i h

  • 8/8/2019 DB2 Appl Day 1

    56/57

    Let us CREATE another table withdifferent column attributes

    ,that value required always it can not be omitted means that if value is not giving it will be assigned as TRAINING WITH DEFAULT NULL means if value is not given NULL will b

    - ,NOT NULL WITH DEFAULT means here data type is CHAR so spac

  • 8/8/2019 DB2 Appl Day 1

    57/57

    DEPT1 table created successfully