DDLvsDDS AS400

Embed Size (px)

Citation preview

  • 8/9/2019 DDLvsDDS AS400

    1/36

     

    • A comparison of tools used to define data

    on the System i.

    • By Robert Berendt

    DDL or DDS?

  • 8/9/2019 DDLvsDDS AS400

    2/36

     

    Data Definition Specifications

      UNIQUE 

    R ITEMMASTR 

    ITEMNBR 17A  COMP(NE ' ')

      ITEMCLAS 2A  COMP(NE ' ')

      PRICE 9P 2  COMP(GT 0) 

    K ITEMNBR 

  • 8/9/2019 DDLvsDDS AS400

    3/36

     

    UPDDTA on DDS file

  • 8/9/2019 DDLvsDDS AS400

    4/36

     

    !S"RT !T# R#B$T"%%AST &ALU"S'( () ( () *+,

    - ros inserted in T"%%AST in R#B.

    S/L a0ainst DDS file

  • 8/9/2019 DDLvsDDS AS400

    5/36

     

    i!a1 a0ainst DDS file

  • 8/9/2019 DDLvsDDS AS400

    6/36

     

    2R"AT" TABL" R#B$DDL%AST

    'T"%!BR 23AR '-4 , !#T !ULL 5T3 D"6AULT)

    PR%AR7 8"7 'T"%!BR,)

    23"28 'T"%!BR9:( ( ,)

    T"%2LAS 23AR '; , !#T !ULL 5T3 D"6AULT)

    23"28 'T"%2LAS9:( ( ,)

    PR2" D"2%AL '< ) ;, !#T !ULL 5T3 D"6AULT)

      23"28 'PR2":= ,,

    R2D6%T DDL%ASTR 

    DDL defined file

  • 8/9/2019 DDLvsDDS AS400

    7/36

     

    !S"RT !T# R#B$DDL%AST &ALU"S'( () ( () *+,

    !S"RT or UPDAT" not alloed by 23"28

    constraint.

    S/L a0ainst DDL file

  • 8/9/2019 DDLvsDDS AS400

    8/36

     

    i!a1 a0ainst DDL file

  • 8/9/2019 DDLvsDDS AS400

    9/36

     

    SQL and DDS Data Validation

    DifferencesThe ma>or difference beteen these to types of physical

    database ob>ects is the process that determines hen the data is

    1alidated. 6or DDS) the data is 1alidated as data is read throu0hthe open cursor. 6or S/L) data is 1alidated as it is ritten

    throu0h the open cursor.

  • 8/9/2019 DDLvsDDS AS400

    10/36

     

    SQL and DDS Data Validation

    Differences

  • 8/9/2019 DDLvsDDS AS400

    11/36

     

    DSPP6% of DDS file

  • 8/9/2019 DDLvsDDS AS400

    12/36

     

    DDS !o chec@ on rite

    CRTPF BADDATA RCDLEN(24)

    *.......1........2....

    !!!!!!!!!!!!!!!!!!!!!!!!

    CP"F FROMFILE(BADDATA) TOFILE(ITEMMAST)

    MBROPT(*ADD) FMTOPT(*NOC#K)

  • 8/9/2019 DDLvsDDS AS400

    13/36

     

    DDS !o has bad data

    ........1........2........$........4..

    ITEMNBR ITEMCLAS PRICE

    A %.00&  .00&

    !!!!!!!!!!!!!!!!! !!

  • 8/9/2019 DDLvsDDS AS400

    14/36

     

     !ot on DDL file

    CP"F FROMFILE(BADDATA) TOFILE(MAST)

      MBROPT(*ADD) FMTOPT(*NOC#K)

    D+ ,--/ 3 3/ ,, DDLMAST.

    D+ ,--/ 3 3/ ,, DDLMAST.

    C

    C/5 -6 5 83 , CPF029.

    E3 :+/ +3 ,, DDLMAST / 8DDLMAST.

    0 53 53- +3 DDLMAST / ROB.

  • 8/9/2019 DDLvsDDS AS400

    15/36

     

    Performance enhancements

    • %any applications ha1e an a1era0e of ;+ reads to e1ery rite.

    f you mo1e the 1alidity chec@in0 to rite time) performance

    ill be better.

    • DDL defaults to R"US"DLT) or reuse deleted records.

    Allos concurrent rite support.

  • 8/9/2019 DDLvsDDS AS400

    16/36

     

    Performance enhancements

    'cont,

    • DDL defined files ill ha1e a C8 pa0e siEe 1s F*G;8

     pa0e siEe from DDS.

  • 8/9/2019 DDLvsDDS AS400

    17/36

     

    Source?

    Store in /DDSSR2) compile ith RU!S/LST%

  • 8/9/2019 DDLvsDDS AS400

    18/36

     

    5hat about column headin0s?

      UNIQUE 

    R ITEMMASTR 

    ITEMNBR 17A  COMP(NE ' ') 

    COL#DG('I+,' 'N;,')

      ITEMCLAS 2A  COMP(NE ' ') 

    COL#DG('I+,' 'C') 

    PRICE 9P 2  COMP(GT 0) 

    COL#DG(' ' 'P5') 

    K ITEMNBR 

  • 8/9/2019 DDLvsDDS AS400

    19/36

     

    2olumn headin0s in S/L

    CREATE TABLE ROB

      PRIMAR" KE" (ITEMNBR)>

      C#ECK (ITEMNBR?@' ' )> ITEMCLAS C#AR (2 ) NOT NULL =IT# DEFAULT>

      C#ECK (ITEMCLAS?@' ' )>

     PRICE DECIMAL (9 > 2) NOT NULL =IT#

    DEFAULT>  C#ECK (PRICE@0 ))

    RCDFMT DDLMASTR

  • 8/9/2019 DDLvsDDS AS400

    20/36

     

    2olumn headin0s

    LABEL ON COLUMN ITEMNBR IS 'I+, N;,'

    LABEL ON COLUMN ITEMCLAS

     IS 'I+, C'

    LABEL ON COLUMN PRICE

     IS 'P5'

  • 8/9/2019 DDLvsDDS AS400

    21/36

     

    6ield Reference 6ile

    2R"AT" TABL" "%PL#7"" AS

    'S"L"2T "%PL#7""HD) !A%") etc.

    6R#% 6"LDR"6,5T3 !# DATA

    7es) it does brin0 the column headin0s alon0.

     !o) it does not brin0 the constraints alon0.

  • 8/9/2019 DDLvsDDS AS400

    22/36

     

    2onstraints

     ITEMCLAS C#AR (2 ) NOT NULL =IT# DEFAULT>

      C#ECK (ITEMCLAS?@' ' )>

      FOREIGN KE" (ITEMCLAS)

      REFERENCES IIC (ICLAS)

      ON DELETE NO ACTION  ON UPDATE NO ACTION>

  • 8/9/2019 DDLvsDDS AS400

    23/36

     

    R2D6%T clause

    n older releases of i+$os S/L did not support the R2D6%T

    clause. 2ommonly hat one did as 2R"AT" TABL" and

    then rename it.

  • 8/9/2019 DDLvsDDS AS400

    24/36

     

    "mbeddin0 UD6Is

    2R"AT" &"5 Pricin0

      AS S"L"2T LPR#D) L/#RD) L2UST) LRDT")

     pricin0'lprod) lJord) lcust) lrdte, as PR2"

      6R#% ordline

  • 8/9/2019 DDLvsDDS AS400

    25/36

     

    %ulti member files

    Partitioned tables

    6orei0n @ey constraints

  • 8/9/2019 DDLvsDDS AS400

    26/36

     

    dentity columns

    CREATE TABLE ROB

     CUSTNBR INTEGER>

     ITEMNBR C#AR (17))

    INSERT INTO ROB ITEMNBR) ALUES(> 'A')

    SELECT * FROM ORDMAST

    ORDNBR CUSTNBR ITEMNBR

      1 A

  • 8/9/2019 DDLvsDDS AS400

    27/36

     

    dentity 1alue

    E5

    ALUES IDENTIT"ALLOCAL() INTO IAR

    D;,- ;/ ;,,6 8 S"SDUMM"1 / ;

    ALUES

    .1 3 ;--3+5+ 3/ 83, 8/ + (

    INSERT INTO ROB ITEMNBR) ALUES(7> 'C'))

  • 8/9/2019 DDLvsDDS AS400

    28/36

     

    ADDP62ST tric@ 

    7ou can use ADDP62ST to add a @ey to a K#UT6L"

  • 8/9/2019 DDLvsDDS AS400

    29/36

     

    C.- 3DD"!

    R#5 23A!M" T%"STA%PCREATE TABLE tickets(

    ticket_ord INTEGER,

    ticket_qty INTEGER,ticket_event VARCHAR(10,

    ticket_ts TI!E"TA!# N$T N%LL

    I!#LICITL& HI''EN

    $R EACH R$) $N %#'ATE A" R$)

    CHANGE TI!E"TA!#*IN"ERT INT$ tickets

    VAL%E"(1,11,+vGA!E1+*

    N$TE- Only 3 column values passed on INSERT

  • 8/9/2019 DDLvsDDS AS400

    30/36

     

    C.- 3DD"!

    R#5 23A!M" T%"STA%P

    SELECT * FROM TICKETS

    TICKETORD TICKETQT" TICKETEENT

      1 11 ,GAME1

    SELECT TICKET_ORD, TICKET_TS FROM TICKETS

    TICKETORD TICKETTS

    1 2009&04&19&22.2.7.10071

  • 8/9/2019 DDLvsDDS AS400

    31/36

     

    C.- L6Is for RLA

    2R"AT" !D"N R#B$%L=-R #! % 'PR#D,

    53"R" DO(%(

    R2D6%T %L=-RR

    ADD PR#D) D"S2) 2LAS

  • 8/9/2019 DDLvsDDS AS400

    32/36

     

    System reference tables

    Select K from /S7S;$S7S2#LU%!S

  • 8/9/2019 DDLvsDDS AS400

    33/36

     

  • 8/9/2019 DDLvsDDS AS400

    34/36

  • 8/9/2019 DDLvsDDS AS400

    35/36

     

    Preparin0 for and Tunin0 the S/L /uery "n0ine on DB; for

    i+$#S

    [email protected]$abstracts$s0;C+J$r 

    Ea>J.pdf 

    DB; Uni1ersal Database for iSeries Administration The

    Mraphical 5ay on &+RG

    [email protected]$abstracts$s0;C=

  • 8/9/2019 DDLvsDDS AS400

    36/36

    AnalyEin0 DB; for i+$#S Performance ith the &+R S/L

    Plan 2ache &isual "plain

    http$$*

    =G.ibm.com$ser1ers$enable$site$education$abstracts$e+;CHabs.

    html